mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-21 12:08:20 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3737418ec3 | ||
|
|
6d47ea7466 | ||
|
|
84d96ff83a | ||
|
|
6e985aed61 | ||
|
|
8347a9ca15 | ||
|
|
ab9b33320d | ||
|
|
efd6163238 | ||
|
|
0e4bdec0e3 | ||
|
|
0eb03b16a4 | ||
|
|
b216773044 | ||
|
|
92801ba14a | ||
|
|
661e836f06 | ||
|
|
fb5c7ecabe | ||
|
|
a390643458 | ||
|
|
9325c71b51 | ||
|
|
2f746d3ce8 | ||
|
|
bdceda4cb6 | ||
|
|
df6e392bf6 | ||
|
|
48b2047a84 | ||
|
|
2b360b2b2c | ||
|
|
5d19e6ddfa | ||
|
|
5e70b6f3ee | ||
|
|
8eab02ab28 |
@@ -1,4 +1,6 @@
|
||||
node_modules
|
||||
dist
|
||||
data
|
||||
Dockerfile*
|
||||
docker-compose*
|
||||
.dockerignore
|
||||
|
||||
@@ -47,6 +47,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
socat \
|
||||
ca-certificates \
|
||||
bubblewrap \
|
||||
gosu \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
@@ -69,5 +70,12 @@ COPY --chown=bun:bun --from=builder /app/prisma.config.ts.prod ./prisma.config.t
|
||||
# Expose port (Bun Hono defaults to 3000)
|
||||
EXPOSE 3000
|
||||
|
||||
# Switch back to root at the end so the container runs the entrypoint as root
|
||||
USER root
|
||||
COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
# Default command: run migrations and start API server
|
||||
CMD ["sh", "-c", "bun prisma migrate deploy && bun index.js"]
|
||||
|
||||
@@ -49,13 +49,32 @@ Docker Compose is the fastest way to get Shumai running. You do not need to clon
|
||||
```bash
|
||||
curl -o docker-compose.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/docker-compose.yaml
|
||||
```
|
||||
3. **Configure Environment Variables (Remote Deployments only):**
|
||||
If deploying Shumai to a remote server (e.g., AWS EC2, VPS), edit docker-compose.yaml and add AWS_ENDPOINT_URL_S3 under the environment section, setting it to your server's public IP address or domain name (e.g., http://12.34.56.78).
|
||||
4. Start the services in detached mode:
|
||||
3. Configure environment variables (optional):
|
||||
|
||||
* `SHUMAI_SERVER_PORT` controls the port the Shumai server listens on. The default is `3000`.
|
||||
* By default, Shumai uses the bundled local storage service in this Docker Compose setup. To use an external S3-compatible storage instead, set `AWS_ENDPOINT_URL_S3` to the provider's endpoint URL and configure the corresponding AWS credentials and bucket settings as needed.
|
||||
```
|
||||
AWS_ENDPOINT_URL_S3: S3_ENDPOINT_URL
|
||||
S3_REGION: S3_REGION
|
||||
S3_BUCKET: BUCKET_NAME
|
||||
S3_ACCESS_KEY_ID: ID
|
||||
S3_SECRET_ACCESS_KEY: KEY
|
||||
```
|
||||
* By default, `AWS_ENDPOINT_URL_S3` is set to: `http://localhost:{SHUMAI_SERVER_PORT}`, if you use local storage and expose Shumai on a custom host/port combination, set `AWS_ENDPOINT_URL_S3` to the external URL that browsers will use to upload files.
|
||||
|
||||
For example, if you change the port mapping in `docker-compose.yaml` from `3000:3000` to `12345:3000` and deploy on a server with IP address `12.34.56.78`, set:
|
||||
|
||||
```bash
|
||||
AWS_ENDPOINT_URL_S3=http://12.34.56.78:12345
|
||||
```
|
||||
|
||||
This value must be reachable from client browsers and should include the externally exposed port.
|
||||
|
||||
5. Start the services in detached mode:
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
5. Open your browser and access Shumai at `http://localhost:3000` (or `http://<your-server-ip>:3000` for remote deployments).
|
||||
6. Open your browser and access Shumai at `http://localhost:3000` (or `http://<your-server-ip>:3000` for remote deployments).
|
||||
|
||||
### Option 2: Install via NPM / Package Manager
|
||||
|
||||
@@ -126,14 +145,18 @@ DATABASE_URL=postgresql://shumai:shumai_password@localhost:5432/shumai_db?schema
|
||||
BETTER_AUTH_SECRET=ySxs7DxzHDZBbeeHNPEwBuspYwipBqz5Gk5XdBjNhWw=
|
||||
STORAGE_BACKEND=local
|
||||
SHUMAI_SERVER_PORT=3000
|
||||
AWS_ENDPOINT_URL_S3=http://localhost
|
||||
AWS_ENDPOINT_URL_S3=http://localhost:3000
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> If deploying on a remote server, update `AWS_ENDPOINT_URL_S3` from `http://localhost` to your server's public IP address or domain name.
|
||||
> `SHUMAI_SERVER_PORT` sets the port the server starts on, while `AWS_ENDPOINT_URL_S3` is used by the browser to build file upload URLs.
|
||||
> If deploying on a remote server (e.g. `http://123.456.7.8`) with a mapped port (e.g. `12345:3000` in docker-compose), set `AWS_ENDPOINT_URL_S3` to `http://123.456.7.8:12345`.
|
||||
|
||||
#### Step 6: Run Shumai
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **For Bun Users:** Since the published package binaries contain a `#!/usr/bin/env node` shebang, running the global command directly (e.g., `shumai`) will execute under Node.js. If you installed with Bun and want to run under the Bun runtime, you must prefix all commands with `bun run --bun` (e.g., `bun run --bun shumai`, `bun run --bun shumai -d`, `bun run --bun shumai stop`).
|
||||
|
||||
Start the application from your workspace folder:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/agent-app",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -26,6 +26,9 @@ export SHUMAI_API_KEY="your-developer-api-token"
|
||||
|
||||
## Usage
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **For Bun Users:** Since the package binary contains a `#!/usr/bin/env node` shebang, running `shumai-cli` directly will run under Node.js. If you wish to run it using Bun, prefix the command with `bun run --bun` (e.g., `bun run --bun shumai-cli project ls`).
|
||||
|
||||
Run `shumai-cli` or query specific commands:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/cli",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/transcode-app",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/web-app",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
|
||||
@@ -17,7 +17,7 @@ services:
|
||||
retries: 5
|
||||
|
||||
shumai:
|
||||
image: shumaione/shumai:main
|
||||
image: shumaione/shumai:latest
|
||||
container_name: shumai_app
|
||||
ports:
|
||||
- '3000:3000'
|
||||
@@ -27,8 +27,12 @@ services:
|
||||
# Database Configuration
|
||||
DATABASE_URL: postgres://shumai:shumai_password@shumai_postgres:5432/shumai_db?search_path=public&sslmode=disable
|
||||
|
||||
# Server Configuration
|
||||
SHUMAI_SERVER_PORT: 3000
|
||||
|
||||
# S3 Configuration
|
||||
STORAGE_BACKEND: local
|
||||
AWS_ENDPOINT_URL_S3: http://localhost:3000
|
||||
|
||||
# Better Auth
|
||||
BETTER_AUTH_SECRET: qSxs9DxzHDZBbeeTNPEwBuspYwipBqz5Gk5XdBjNhWw=
|
||||
|
||||
@@ -37,16 +37,28 @@ Shumai is configured via environment variables. You can define these variables i
|
||||
|
||||
Shumai supports storing files locally or on S3-compatible endpoints.
|
||||
|
||||
| Variable | Description | Example / Default |
|
||||
| :------------------------- | :------------------------------------------------------------------------------------------------ | :--------------------------- |
|
||||
| `STORAGE_BACKEND` | Storage type. Use `local` for local file system storage, or `s3` for S3-compatible cloud storage. | `local` (default) or `s3` |
|
||||
| `AWS_ENDPOINT_URL_S3` | Custom endpoint for S3 storage. Must change to public domain/IP if deploying remotely. | `http://localhost` (default) |
|
||||
| `S3_BUCKET` | S3 bucket name. | `shumai` (default) |
|
||||
| `S3_ACCESS_KEY_ID` | Access key credentials for S3. | `minioadmin` (default) |
|
||||
| `S3_SECRET_ACCESS_KEY` | Secret key credentials for S3. | `minioadmin` (default) |
|
||||
| `S3_REGION` | S3 storage region. | `auto` (default) |
|
||||
| `S3_USE_SSL` | Set to `true` to use HTTPS for S3 endpoints. | `false` (default) |
|
||||
| `PRESIGNED_URL_EXPIRES_IN` | Number of hours for which generated presigned download/upload links are valid. | `5` (default) |
|
||||
| Variable | Description | Example / Default |
|
||||
| :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------ |
|
||||
| `STORAGE_BACKEND` | Storage type. Use `local` for local file system storage, or `s3` for S3-compatible cloud storage. | `local` (default) or `s3` |
|
||||
| `AWS_ENDPOINT_URL_S3` | Endpoint for S3 storage or local storage. Used by the browser to build file upload URLs. Must include port if deploying remotely or using custom ports. | `http://localhost:3000` (respects `SHUMAI_SERVER_PORT` fallback if unset) |
|
||||
| `S3_BUCKET` | S3 bucket name. | `shumai` (default) |
|
||||
| `S3_ACCESS_KEY_ID` | Access key credentials for S3. | `minioadmin` (default) |
|
||||
| `S3_SECRET_ACCESS_KEY` | Secret key credentials for S3. | `minioadmin` (default) |
|
||||
| `S3_REGION` | S3 storage region. | `auto` (default) |
|
||||
| `S3_USE_SSL` | Set to `true` to use HTTPS for S3 endpoints. | `false` (default) |
|
||||
| `PRESIGNED_URL_EXPIRES_IN` | Number of hours for which generated presigned download/upload links are valid. | `5` (default) |
|
||||
|
||||
### Local Storage Port Configuration
|
||||
|
||||
When `STORAGE_BACKEND` is set to `local` (default):
|
||||
|
||||
- `SHUMAI_SERVER_PORT` configures the port on which the Shumai web server starts and listens.
|
||||
- `AWS_ENDPOINT_URL_S3` configures the public/external endpoint used by client browsers to upload and download files. It must include the scheme and port.
|
||||
|
||||
For example, if you deploy Shumai on a remote server at `http://123.456.7.8` and configure port mapping `12345:3000` (exposing port 3000 internally as port 12345 externally) in Docker Compose:
|
||||
|
||||
- Set `SHUMAI_SERVER_PORT` to `3000`.
|
||||
- Set `AWS_ENDPOINT_URL_S3` to `http://123.456.7.8:12345`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -80,3 +80,6 @@ Run this on your sandboxed agent execution nodes (requires sandbox dependencies
|
||||
npm install -g @shumai-one/shumai-agent
|
||||
shumai-agent
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **For Bun Users:** Since the worker package binaries contain a `#!/usr/bin/env node` shebang, running `shumai-transcode` or `shumai-agent` directly will run under Node.js. If you wish to run them using Bun, prefix the commands with `bun run --bun` (e.g., `bun run --bun shumai-transcode` or `bun run --bun shumai-agent`).
|
||||
|
||||
@@ -61,20 +61,32 @@ To handle media processing and security isolation, the host machine must have th
|
||||
```
|
||||
3. **Configure Environment Variables**:
|
||||
Create a new directory, navigate into it, and create a `.env` file:
|
||||
|
||||
```bash
|
||||
mkdir shumai && cd shumai
|
||||
```
|
||||
|
||||
Create a `.env` file with the following variables:
|
||||
|
||||
```env
|
||||
DATABASE_URL=postgresql://shumai:shumai_password@localhost:5432/shumai_db?schema=public
|
||||
BETTER_AUTH_SECRET=your-random-32-character-secret-key
|
||||
STORAGE_BACKEND=local
|
||||
AWS_ENDPOINT_URL_S3=http://localhost
|
||||
AWS_ENDPOINT_URL_S3=http://localhost:3000
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
> `AWS_ENDPOINT_URL_S3` must include the scheme and port (e.g. `http://localhost:3000`) where Shumai is publicly accessible. This URL is used directly by client browsers for file uploads.
|
||||
|
||||
4. **Start Shumai**:
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **For Bun Users:** Since the published package binaries contain a `#!/usr/bin/env node` shebang, running `shumai` directly will execute under Node.js. If you installed using Bun and want to run it under the Bun runtime, prefix the command with `bun run --bun` (e.g., `bun run --bun shumai`).
|
||||
|
||||
```bash
|
||||
shumai
|
||||
```
|
||||
|
||||
Open your browser to `http://localhost:3000`.
|
||||
|
||||
---
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "shumai",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"repository": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/agent",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/api",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Hono } from 'hono'
|
||||
import type { Context } from 'hono'
|
||||
import { zValidator } from '@hono/zod-validator'
|
||||
import { shareService } from '@shumai/core/src/share/share'
|
||||
import { assetService } from '@shumai/core/src/asset/asset'
|
||||
@@ -11,6 +12,12 @@ import { auth } from '@shumai/core/src/auth/auth'
|
||||
import { prisma } from '@shumai/db'
|
||||
import { createCommentRequestSchema } from '@shumai/dtos'
|
||||
import { notificationService } from '@shumai/core/src/notification/notification'
|
||||
import {
|
||||
ShareLinkNotFoundError,
|
||||
ShareLinkDisabledError,
|
||||
ShareLinkExpiredError,
|
||||
ShareLinkPasswordInvalidError,
|
||||
} from '@shumai/core/src/share/errors'
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
@@ -30,6 +37,22 @@ function toFieldInfo(
|
||||
}
|
||||
}
|
||||
|
||||
export function handlePublicShareError(c: Context, err: unknown) {
|
||||
if (err instanceof ShareLinkPasswordInvalidError) {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
if (err instanceof ShareLinkExpiredError || err instanceof ShareLinkDisabledError) {
|
||||
const msg = err instanceof Error ? err.message : String(err)
|
||||
return c.json({ error: msg }, 403)
|
||||
}
|
||||
if (err instanceof ShareLinkNotFoundError) {
|
||||
const msg = err instanceof Error ? err.message : String(err)
|
||||
return c.json({ error: msg }, 404)
|
||||
}
|
||||
const msg = err instanceof Error ? err.message : String(err)
|
||||
return c.json({ error: msg }, 500)
|
||||
}
|
||||
|
||||
const sharedChildrenRequestSchema = paginationParamsSchema.extend({
|
||||
assetType: z.string().optional(),
|
||||
})
|
||||
@@ -37,8 +60,10 @@ const sharedChildrenRequestSchema = paginationParamsSchema.extend({
|
||||
const route = app
|
||||
.get('/shares/:shareId/info', async (c) => {
|
||||
const shareId = c.req.param('shareId')
|
||||
const password = c.req.header('x-share-password')
|
||||
try {
|
||||
const shareLink = await shareService.getShareLink(shareId)
|
||||
await shareService.verifyPublicAccess(shareLink.rootFolderId, password)
|
||||
return c.json({
|
||||
id: shareLink.id,
|
||||
name: shareLink.name,
|
||||
@@ -52,7 +77,7 @@ const route = app
|
||||
defaultSortOrder: shareLink.defaultSortOrder,
|
||||
})
|
||||
} catch (err) {
|
||||
return c.json({ error: (err as Error).message }, 404)
|
||||
return handlePublicShareError(c, err)
|
||||
}
|
||||
})
|
||||
.get('/shares/:shareId/fields', async (c) => {
|
||||
@@ -72,14 +97,7 @@ const route = app
|
||||
.map((f) => toFieldInfo(f.field, f.visible)),
|
||||
)
|
||||
} catch (err) {
|
||||
const msg = (err as Error).message
|
||||
if (msg === 'Invalid password for share link') {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
if (msg === 'Share link has expired' || msg === 'Share link is disabled') {
|
||||
return c.json({ error: msg }, 403)
|
||||
}
|
||||
return c.json({ error: msg }, 500)
|
||||
return handlePublicShareError(c, err)
|
||||
}
|
||||
})
|
||||
.get(
|
||||
@@ -112,14 +130,7 @@ const route = app
|
||||
|
||||
return c.json(res)
|
||||
} catch (err) {
|
||||
const msg = (err as Error).message
|
||||
if (msg === 'Invalid password for share link') {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
if (msg === 'Share link has expired' || msg === 'Share link is disabled') {
|
||||
return c.json({ error: msg }, 403)
|
||||
}
|
||||
return c.json({ error: msg }, 500)
|
||||
return handlePublicShareError(c, err)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -133,14 +144,7 @@ const route = app
|
||||
const asset = await assetService.getAsset({ assetId: fileId })
|
||||
return c.json(asset)
|
||||
} catch (err) {
|
||||
const msg = (err as Error).message
|
||||
if (msg === 'Invalid password for share link') {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
if (msg === 'Share link has expired' || msg === 'Share link is disabled') {
|
||||
return c.json({ error: msg }, 403)
|
||||
}
|
||||
return c.json({ error: msg }, 500)
|
||||
return handlePublicShareError(c, err)
|
||||
}
|
||||
})
|
||||
.get(
|
||||
@@ -158,14 +162,7 @@ const route = app
|
||||
const res = await assetService.listComments(targetFileId, req)
|
||||
return c.json(res)
|
||||
} catch (err) {
|
||||
const msg = (err as Error).message
|
||||
if (msg === 'Invalid password for share link') {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
if (msg === 'Share link has expired' || msg === 'Share link is disabled') {
|
||||
return c.json({ error: msg }, 403)
|
||||
}
|
||||
return c.json({ error: msg }, 500)
|
||||
return handlePublicShareError(c, err)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -237,14 +234,7 @@ const route = app
|
||||
|
||||
return c.json(comment, 201)
|
||||
} catch (err) {
|
||||
const msg = (err as Error).message
|
||||
if (msg === 'Invalid password for share link') {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
if (msg === 'Share link has expired' || msg === 'Share link is disabled') {
|
||||
return c.json({ error: msg }, 403)
|
||||
}
|
||||
return c.json({ error: msg }, 500)
|
||||
return handlePublicShareError(c, err)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { authMiddleware } from './middleware/auth'
|
||||
import { shareService } from '@shumai/core/src/share/share'
|
||||
import { assetService } from '@shumai/core/src/asset/asset'
|
||||
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
||||
import { ShareLinkPasswordInvalidError, ShareLinkExpiredError } from '@shumai/core/src/share/errors'
|
||||
|
||||
vi.mock('./middleware/auth', () => ({
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -57,15 +58,74 @@ describe('Share API', () => {
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
|
||||
id: 'share1',
|
||||
name: 'Public Share',
|
||||
rootFolderId: 'folder1',
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const res = await app.request('/shares/share1/info', {
|
||||
method: 'GET',
|
||||
headers: { 'x-share-password': 'pass' },
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body.name).toBe('Public Share')
|
||||
expect(body.hasPassword).toBe(true)
|
||||
expect(shareService.verifyPublicAccess).toHaveBeenCalledWith('folder1', 'pass')
|
||||
})
|
||||
|
||||
test('Unauthorized', async () => {
|
||||
vi.spyOn(shareService, 'getShareLink').mockResolvedValue({
|
||||
id: 'share1',
|
||||
name: 'Public Share',
|
||||
isDisabled: false,
|
||||
isExpired: false,
|
||||
hasPassword: true,
|
||||
rootFolderId: 'folder1',
|
||||
projectId: 'project1',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockRejectedValue(
|
||||
new ShareLinkPasswordInvalidError('Invalid password for share link'),
|
||||
)
|
||||
|
||||
const res = await app.request('/shares/share1/info', {
|
||||
method: 'GET',
|
||||
headers: { 'x-share-password': 'wrong' },
|
||||
})
|
||||
|
||||
expect(res.status).toBe(401)
|
||||
const body = await res.json()
|
||||
expect(body.error).toBe('Unauthorized')
|
||||
})
|
||||
|
||||
test('Expired/Disabled', async () => {
|
||||
vi.spyOn(shareService, 'getShareLink').mockResolvedValue({
|
||||
id: 'share1',
|
||||
name: 'Public Share',
|
||||
isDisabled: false,
|
||||
isExpired: false,
|
||||
hasPassword: true,
|
||||
rootFolderId: 'folder1',
|
||||
projectId: 'project1',
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
vi.spyOn(shareService, 'verifyPublicAccess').mockRejectedValue(
|
||||
new ShareLinkExpiredError('Share link has expired'),
|
||||
)
|
||||
|
||||
const res = await app.request('/shares/share1/info', {
|
||||
method: 'GET',
|
||||
})
|
||||
|
||||
expect(res.status).toBe(403)
|
||||
const body = await res.json()
|
||||
expect(body.error).toBe('Share link has expired')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/core",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -191,4 +191,39 @@ describe('S3Service implementations', () => {
|
||||
await expect(localS3.presign('b', 'k', 'POST')).rejects.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('s3Service initialization', () => {
|
||||
let originalEnv: NodeJS.ProcessEnv
|
||||
|
||||
beforeEach(() => {
|
||||
originalEnv = { ...process.env }
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.env = originalEnv
|
||||
})
|
||||
|
||||
it('should initialize LocalStorageService with default localhost and SHUMAI_SERVER_PORT when AWS_ENDPOINT_URL_S3 is not set', async () => {
|
||||
process.env.STORAGE_BACKEND = 'local'
|
||||
delete process.env.AWS_ENDPOINT_URL_S3
|
||||
process.env.SHUMAI_SERVER_PORT = '4567'
|
||||
|
||||
vi.resetModules()
|
||||
const { s3Service } = await import('./s3')
|
||||
const url = await s3Service.presign('bucket', 'key', 'GET')
|
||||
expect(url).toContain('http://localhost:4567')
|
||||
})
|
||||
|
||||
it('should initialize LocalStorageService with exact AWS_ENDPOINT_URL_S3 when it is set', async () => {
|
||||
process.env.STORAGE_BACKEND = 'local'
|
||||
process.env.AWS_ENDPOINT_URL_S3 = 'http://123.456.7.8:12345'
|
||||
process.env.SHUMAI_SERVER_PORT = '4567'
|
||||
|
||||
vi.resetModules()
|
||||
const { s3Service } = await import('./s3')
|
||||
const url = await s3Service.presign('bucket', 'key', 'GET')
|
||||
expect(url).toContain('http://123.456.7.8:12345')
|
||||
expect(url).not.toContain('4567')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -452,7 +452,7 @@ export class LocalStorageService implements S3Service {
|
||||
|
||||
const storageBackend = process.env.STORAGE_BACKEND || 'local'
|
||||
const port = process.env.SHUMAI_SERVER_PORT || '3000'
|
||||
const s3Endpoint = process.env.AWS_ENDPOINT_URL_S3 || 'http://localhost'
|
||||
const s3Endpoint = process.env.AWS_ENDPOINT_URL_S3 || `http://localhost:${port}`
|
||||
|
||||
export const s3Service: S3Service =
|
||||
storageBackend === 's3'
|
||||
@@ -464,4 +464,4 @@ export const s3Service: S3Service =
|
||||
process.env.S3_USE_SSL === 'true',
|
||||
process.env.S3_REGION || 'auto',
|
||||
)
|
||||
: new LocalStorageService(`${s3Endpoint}:${port}`)
|
||||
: new LocalStorageService(s3Endpoint)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
export class ShareLinkNotFoundError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'ShareLinkNotFoundError'
|
||||
Object.setPrototypeOf(this, ShareLinkNotFoundError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class ShareLinkDisabledError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'ShareLinkDisabledError'
|
||||
Object.setPrototypeOf(this, ShareLinkDisabledError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class ShareLinkExpiredError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'ShareLinkExpiredError'
|
||||
Object.setPrototypeOf(this, ShareLinkExpiredError.prototype)
|
||||
}
|
||||
}
|
||||
|
||||
export class ShareLinkPasswordInvalidError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'ShareLinkPasswordInvalidError'
|
||||
Object.setPrototypeOf(this, ShareLinkPasswordInvalidError.prototype)
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,12 @@ import {
|
||||
} from '@shumai/dtos'
|
||||
import { PaginatedData, paginateQuery } from '@shumai/core/src/pagination'
|
||||
import { getAvatarUrl } from '@shumai/core/src/user/avatar'
|
||||
import {
|
||||
ShareLinkNotFoundError,
|
||||
ShareLinkDisabledError,
|
||||
ShareLinkExpiredError,
|
||||
ShareLinkPasswordInvalidError,
|
||||
} from './errors'
|
||||
|
||||
export class ShareService {
|
||||
async createShareLink(
|
||||
@@ -143,7 +149,7 @@ export class ShareService {
|
||||
where: { id: shareLinkId },
|
||||
include: { creator: true },
|
||||
})
|
||||
if (!shareLink) throw new Error('Share link not found')
|
||||
if (!shareLink) throw new ShareLinkNotFoundError('Share link not found')
|
||||
return await this.toShareLinkInfo(shareLink)
|
||||
}
|
||||
|
||||
@@ -264,7 +270,7 @@ export class ShareService {
|
||||
`
|
||||
|
||||
if (rows.length === 0) {
|
||||
throw new Error('Asset is not shared')
|
||||
throw new ShareLinkNotFoundError('Asset is not shared')
|
||||
}
|
||||
|
||||
const shareRootId = rows[0].shareRootId
|
||||
@@ -273,19 +279,19 @@ export class ShareService {
|
||||
})
|
||||
|
||||
if (!shareLink) {
|
||||
throw new Error('Share link not found for this asset')
|
||||
throw new ShareLinkNotFoundError('Share link not found for this asset')
|
||||
}
|
||||
|
||||
if (shareLink.isDisabled) {
|
||||
throw new Error('Share link is disabled')
|
||||
throw new ShareLinkDisabledError('Share link is disabled')
|
||||
}
|
||||
|
||||
if (shareLink.expireAt && shareLink.expireAt < new Date()) {
|
||||
throw new Error('Share link has expired')
|
||||
throw new ShareLinkExpiredError('Share link has expired')
|
||||
}
|
||||
|
||||
if (shareLink.password && shareLink.password !== providedPassword) {
|
||||
throw new Error('Invalid password for share link')
|
||||
throw new ShareLinkPasswordInvalidError('Invalid password for share link')
|
||||
}
|
||||
|
||||
return shareLink
|
||||
@@ -301,6 +307,7 @@ export class ShareService {
|
||||
expireAt: l.expireAt?.toISOString(),
|
||||
isDisabled: l.isDisabled,
|
||||
hasPassword: !!l.password,
|
||||
password: l.password,
|
||||
defaultSortOrder: l.defaultSortOrder,
|
||||
viewMode: l.viewMode,
|
||||
fieldVisibility: l.fieldVisibility as Record<string, boolean> | undefined,
|
||||
|
||||
@@ -58,7 +58,7 @@ export class VersionStackService {
|
||||
throw new Error('parent not found')
|
||||
}
|
||||
|
||||
const firstFile = files[0]
|
||||
const firstFile = files.find((f) => f.id === fileIds[0])
|
||||
const sortIndex = firstFile?.sortIndex || null
|
||||
|
||||
const stack = await tx.asset.create({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/db",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/dtos",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface ShareLinkInfo {
|
||||
expireAt?: string
|
||||
isDisabled: boolean
|
||||
hasPassword: boolean
|
||||
password?: string | null
|
||||
defaultSortOrder?: string
|
||||
viewMode?: string
|
||||
fieldVisibility?: Record<string, boolean>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/tableprinter",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/transcode",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -469,7 +469,7 @@ export function FolderTree({
|
||||
|
||||
<ScrollArea
|
||||
className={cn(
|
||||
'flex-1 min-h-0 transition-all duration-300 ease-in-out',
|
||||
'flex-1 min-h-0 transition-all duration-300 ease-in-out [&>div>div]:block!',
|
||||
isAssetsExpanded
|
||||
? 'opacity-100 visible pointer-events-auto'
|
||||
: 'opacity-0 invisible pointer-events-none h-0',
|
||||
@@ -569,7 +569,7 @@ export function FolderTree({
|
||||
|
||||
<ScrollArea
|
||||
className={cn(
|
||||
'flex-1 min-h-0 transition-all duration-300 ease-in-out',
|
||||
'flex-1 min-h-0 transition-all duration-300 ease-in-out [&>div>div]:block!',
|
||||
isCollectionsExpanded
|
||||
? 'opacity-100 visible pointer-events-auto'
|
||||
: 'opacity-0 invisible pointer-events-none h-0',
|
||||
@@ -599,7 +599,7 @@ export function FolderTree({
|
||||
<div
|
||||
key={collection.id}
|
||||
className={cn(
|
||||
'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground min-w-0',
|
||||
isColActive && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
|
||||
)}
|
||||
onClick={() =>
|
||||
@@ -620,7 +620,7 @@ export function FolderTree({
|
||||
|
||||
{canEdit && (
|
||||
<div
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<DropdownMenu modal={false}>
|
||||
@@ -705,7 +705,7 @@ export function FolderTree({
|
||||
|
||||
<ScrollArea
|
||||
className={cn(
|
||||
'flex-1 min-h-0 transition-all duration-300 ease-in-out',
|
||||
'flex-1 min-h-0 transition-all duration-300 ease-in-out [&>div>div]:block!',
|
||||
isSharesExpanded
|
||||
? 'opacity-100 visible pointer-events-auto'
|
||||
: 'opacity-0 invisible pointer-events-none h-0',
|
||||
@@ -958,7 +958,7 @@ function ShareLinkItem({
|
||||
<div
|
||||
ref={setDroppableRef}
|
||||
className={cn(
|
||||
'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground min-w-0',
|
||||
isActive && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
|
||||
isOver && isValidDropTarget && 'bg-sidebar-accent ring-2 ring-primary ring-inset',
|
||||
)}
|
||||
@@ -978,7 +978,7 @@ function ShareLinkItem({
|
||||
|
||||
{canEdit && (
|
||||
<div
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<DropdownMenu modal={false}>
|
||||
@@ -1176,7 +1176,7 @@ function FolderTreeItem({
|
||||
<div
|
||||
ref={setNodeRef}
|
||||
className={cn(
|
||||
'group flex cursor-pointer items-center gap-1 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
'group flex cursor-pointer items-center gap-1 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground min-w-0',
|
||||
(isActive || isSelected) &&
|
||||
'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
|
||||
isDragging && 'opacity-50',
|
||||
@@ -1188,7 +1188,10 @@ function FolderTreeItem({
|
||||
onClick={handleFolderClick}
|
||||
>
|
||||
{!isRoot && (
|
||||
<button onClick={handleToggleExpand} className="flex h-4 w-4 items-center justify-center">
|
||||
<button
|
||||
onClick={handleToggleExpand}
|
||||
className="flex h-4 w-4 items-center justify-center shrink-0"
|
||||
>
|
||||
{isExpanded ? (
|
||||
<ChevronDown className="h-3 w-3" />
|
||||
) : (
|
||||
@@ -1197,15 +1200,15 @@ function FolderTreeItem({
|
||||
</button>
|
||||
)}
|
||||
{isRoot ? (
|
||||
<Clapperboard className="h-4 w-4 text-sidebar-primary" />
|
||||
<Clapperboard className="h-4 w-4 text-sidebar-primary shrink-0" />
|
||||
) : (
|
||||
<Folder className="h-4 w-4 text-sidebar-primary" />
|
||||
<Folder className="h-4 w-4 text-sidebar-primary shrink-0" />
|
||||
)}
|
||||
<span className="flex-1 truncate text-sidebar-foreground">{folder.name}</span>
|
||||
|
||||
{canEdit && !isRoot && (
|
||||
<div
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
className="opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<DropdownMenu modal={false}>
|
||||
|
||||
@@ -21,48 +21,81 @@ import type { Annotation } from '@/ui/types'
|
||||
import { useNavigate } from '@tanstack/react-router'
|
||||
|
||||
interface PublicShareManagerProps {
|
||||
shareInfo: {
|
||||
id: string
|
||||
name: string
|
||||
expireAt: string | null
|
||||
isDisabled: boolean
|
||||
isExpired: boolean
|
||||
hasPassword: boolean
|
||||
rootFolderId: string
|
||||
projectId: string
|
||||
viewMode?: string | null
|
||||
defaultSortOrder?: string | null
|
||||
}
|
||||
shareId: string
|
||||
initialFolderId?: string
|
||||
initialFileId?: string
|
||||
startTime?: number
|
||||
}
|
||||
|
||||
interface PublicShareInfo {
|
||||
id: string
|
||||
name: string
|
||||
expireAt: string | null
|
||||
isDisabled: boolean
|
||||
isExpired: boolean
|
||||
hasPassword: boolean
|
||||
rootFolderId: string
|
||||
projectId: string
|
||||
viewMode?: string | null
|
||||
defaultSortOrder?: string | null
|
||||
}
|
||||
|
||||
export function PublicShareManager({
|
||||
shareInfo,
|
||||
shareId,
|
||||
initialFolderId,
|
||||
initialFileId,
|
||||
startTime,
|
||||
}: PublicShareManagerProps) {
|
||||
const navigate = useNavigate()
|
||||
const [password, setPassword] = useState(() => {
|
||||
return localStorage.getItem(`share_pwd_${shareInfo.id}`) || ''
|
||||
return localStorage.getItem(`share_pwd_${shareId}`) || ''
|
||||
})
|
||||
const [passwordInput, setPasswordInput] = useState('')
|
||||
const [isPasswordValid, setIsPasswordValid] = useState(!shareInfo.hasPassword || !!password)
|
||||
|
||||
const currentFolderId = initialFolderId || shareInfo.rootFolderId
|
||||
const {
|
||||
data: shareInfo,
|
||||
error: shareInfoError,
|
||||
isLoading: isShareInfoLoading,
|
||||
} = useQuery<PublicShareInfo>({
|
||||
queryKey: ['share-info', shareId, password],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get(
|
||||
{
|
||||
param: { shareId },
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'x-share-password': password,
|
||||
},
|
||||
},
|
||||
)
|
||||
if (res.status === 401) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
if (res.status === 403) {
|
||||
const body = (await res.json()) as { error?: string }
|
||||
throw new Error(body.error || 'Forbidden')
|
||||
}
|
||||
if (!res.ok) {
|
||||
throw new Error('Failed to fetch share info')
|
||||
}
|
||||
return (await res.json()) as unknown as PublicShareInfo
|
||||
},
|
||||
retry: false,
|
||||
})
|
||||
|
||||
const currentFolderId = initialFolderId || shareInfo?.rootFolderId
|
||||
const viewingFileId = initialFileId || null
|
||||
|
||||
const [ancestorFolders, setAncestorFolders] = useState<AncestorFolder[]>([])
|
||||
|
||||
// Fetch ancestors for breadcrumb
|
||||
const { data: folderInfo } = useQuery({
|
||||
queryKey: ['public-share-folder', shareInfo.id, currentFolderId, password],
|
||||
queryKey: ['public-share-folder', shareId, currentFolderId, password],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].files[':fileId'].$get(
|
||||
{
|
||||
param: { shareId: shareInfo.id, fileId: currentFolderId },
|
||||
param: { shareId, fileId: currentFolderId! },
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -73,11 +106,11 @@ export function PublicShareManager({
|
||||
if (res.status === 401) throw new Error('Unauthorized')
|
||||
return (await res.json()) as unknown as AssetInfo
|
||||
},
|
||||
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled,
|
||||
enabled: !!shareInfo && !!currentFolderId,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (folderInfo?.ancestorFolders) {
|
||||
if (folderInfo?.ancestorFolders && shareInfo) {
|
||||
// Filter ancestors to only those within the share root
|
||||
const rootIndex = folderInfo.ancestorFolders.findIndex((f) => f.id === shareInfo.rootFolderId)
|
||||
if (rootIndex !== -1) {
|
||||
@@ -86,7 +119,7 @@ export function PublicShareManager({
|
||||
setAncestorFolders([])
|
||||
}
|
||||
}
|
||||
}, [folderInfo, shareInfo.rootFolderId, currentFolderId])
|
||||
}, [folderInfo, shareInfo, currentFolderId])
|
||||
|
||||
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
|
||||
const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
|
||||
@@ -103,11 +136,11 @@ export function PublicShareManager({
|
||||
isFetchingNextPage: isFetchingNextFoldersPage,
|
||||
error: foldersError,
|
||||
} = useInfiniteQuery<AssetInfoPaginatedList>({
|
||||
queryKey: ['public-share-children', shareInfo.id, currentFolderId, 'folder', password],
|
||||
queryKey: ['public-share-children', shareId, currentFolderId, 'folder', password],
|
||||
queryFn: async ({ pageParam }) => {
|
||||
const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get(
|
||||
{
|
||||
param: { shareId: shareInfo.id, folderId: currentFolderId },
|
||||
param: { shareId, folderId: currentFolderId! },
|
||||
query: {
|
||||
assetType: 'folder',
|
||||
after: pageParam as string,
|
||||
@@ -123,7 +156,7 @@ export function PublicShareManager({
|
||||
if (res.status === 403) throw new Error('Expired')
|
||||
return (await res.json()) as unknown as AssetInfoPaginatedList
|
||||
},
|
||||
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled,
|
||||
enabled: !!shareInfo && !!currentFolderId,
|
||||
initialPageParam: '',
|
||||
getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined,
|
||||
retry: false,
|
||||
@@ -135,11 +168,11 @@ export function PublicShareManager({
|
||||
hasNextPage: hasNextPageFiles,
|
||||
isFetchingNextPage: isFetchingNextFilesPage,
|
||||
} = useInfiniteQuery<AssetInfoPaginatedList>({
|
||||
queryKey: ['public-share-children', shareInfo.id, currentFolderId, 'file', password],
|
||||
queryKey: ['public-share-children', shareId, currentFolderId, 'file', password],
|
||||
queryFn: async ({ pageParam }) => {
|
||||
const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get(
|
||||
{
|
||||
param: { shareId: shareInfo.id, folderId: currentFolderId },
|
||||
param: { shareId, folderId: currentFolderId! },
|
||||
query: {
|
||||
assetType: 'file',
|
||||
after: pageParam as string,
|
||||
@@ -155,18 +188,18 @@ export function PublicShareManager({
|
||||
if (res.status === 403) throw new Error('Expired')
|
||||
return (await res.json()) as unknown as AssetInfoPaginatedList
|
||||
},
|
||||
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled,
|
||||
enabled: !!shareInfo && !!currentFolderId,
|
||||
initialPageParam: '',
|
||||
getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined,
|
||||
retry: false,
|
||||
})
|
||||
|
||||
const { data: publicFields } = useQuery({
|
||||
queryKey: ['public-share-fields', shareInfo.id, password],
|
||||
queryKey: ['public-share-fields', shareId, password],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].fields.$get(
|
||||
{
|
||||
param: { shareId: shareInfo.id },
|
||||
param: { shareId },
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -177,15 +210,15 @@ export function PublicShareManager({
|
||||
if (res.status === 401) throw new Error('Unauthorized')
|
||||
return (await res.json()) as unknown as FieldInfo[]
|
||||
},
|
||||
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled,
|
||||
enabled: !!shareInfo,
|
||||
})
|
||||
|
||||
const { data: viewingFileData, isLoading: isViewingFileLoading } = useQuery({
|
||||
queryKey: ['public-share-file', shareInfo.id, viewingFileId, password],
|
||||
queryKey: ['public-share-file', shareId, viewingFileId, password],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].files[':fileId'].$get(
|
||||
{
|
||||
param: { shareId: shareInfo.id, fileId: viewingFileId! },
|
||||
param: { shareId, fileId: viewingFileId! },
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -196,16 +229,15 @@ export function PublicShareManager({
|
||||
if (res.status === 401) throw new Error('Unauthorized')
|
||||
return (await res.json()) as unknown as AssetInfo
|
||||
},
|
||||
enabled: !!viewingFileId && isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled,
|
||||
enabled: !!viewingFileId && !!shareInfo,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (foldersError?.message === 'Unauthorized') {
|
||||
setIsPasswordValid(false)
|
||||
setPassword('')
|
||||
localStorage.removeItem(`share_pwd_${shareInfo.id}`)
|
||||
localStorage.removeItem(`share_pwd_${shareId}`)
|
||||
}
|
||||
}, [foldersError, shareInfo.id])
|
||||
}, [foldersError, shareId])
|
||||
|
||||
const folders = useMemo(
|
||||
() => foldersData?.pages.flatMap((page) => page.data ?? []) ?? [],
|
||||
@@ -226,21 +258,20 @@ export function PublicShareManager({
|
||||
const handlePasswordSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setPassword(passwordInput)
|
||||
setIsPasswordValid(true)
|
||||
localStorage.setItem(`share_pwd_${shareInfo.id}`, passwordInput)
|
||||
localStorage.setItem(`share_pwd_${shareId}`, passwordInput)
|
||||
}
|
||||
|
||||
const handleItemDoubleClick = (item: AssetInfo) => {
|
||||
if (item.type === 'folder' || item.targetType === 'folder') {
|
||||
navigate({
|
||||
to: '/share/$shareId/folders/$folderId',
|
||||
params: { shareId: shareInfo.id, folderId: item.id! },
|
||||
params: { shareId, folderId: item.id! },
|
||||
})
|
||||
} else {
|
||||
navigate({
|
||||
to: '/share/$shareId/files/$fileId',
|
||||
params: {
|
||||
shareId: shareInfo.id,
|
||||
shareId,
|
||||
fileId: item.versionStack ? item.versionStack.id : item.id!,
|
||||
},
|
||||
})
|
||||
@@ -249,17 +280,18 @@ export function PublicShareManager({
|
||||
}
|
||||
|
||||
const handleBreadcrumbClick = (folderId: string) => {
|
||||
if (!shareInfo) return
|
||||
const targetId = folderId === 'root' ? shareInfo.rootFolderId : folderId
|
||||
|
||||
if (targetId === shareInfo.rootFolderId) {
|
||||
navigate({
|
||||
to: '/share/$shareId',
|
||||
params: { shareId: shareInfo.id },
|
||||
params: { shareId },
|
||||
})
|
||||
} else {
|
||||
navigate({
|
||||
to: '/share/$shareId/folders/$folderId',
|
||||
params: { shareId: shareInfo.id, folderId: targetId },
|
||||
params: { shareId, folderId: targetId },
|
||||
})
|
||||
}
|
||||
setSelectedIds(new Set())
|
||||
@@ -294,7 +326,7 @@ export function PublicShareManager({
|
||||
const { setProjectState, clearProjectState } = useTopNavStore()
|
||||
|
||||
useEffect(() => {
|
||||
if (isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled) {
|
||||
if (shareInfo && currentFolderId) {
|
||||
const currentFolderName =
|
||||
currentFolderId === shareInfo.rootFolderId
|
||||
? shareInfo.name
|
||||
@@ -315,7 +347,7 @@ export function PublicShareManager({
|
||||
},
|
||||
isRootFolder: currentFolderId === shareInfo.rootFolderId && !viewingFileId,
|
||||
isPublic: true,
|
||||
shareId: shareInfo.id,
|
||||
shareId,
|
||||
fileId: viewingFileId || undefined,
|
||||
onFolderClick: handleBreadcrumbClick,
|
||||
isRightSidebarCollapsed,
|
||||
@@ -325,7 +357,6 @@ export function PublicShareManager({
|
||||
|
||||
return () => clearProjectState()
|
||||
}, [
|
||||
isPasswordValid,
|
||||
shareInfo,
|
||||
currentFolderId,
|
||||
folders,
|
||||
@@ -339,49 +370,73 @@ export function PublicShareManager({
|
||||
|
||||
let content
|
||||
|
||||
if (shareInfo.isExpired || shareInfo.isDisabled) {
|
||||
if (isShareInfoLoading && !shareInfoError) {
|
||||
content = (
|
||||
<div className="flex flex-1 items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10">
|
||||
<AlertCircle className="h-6 w-6 text-destructive" />
|
||||
</div>
|
||||
<CardTitle>Share {shareInfo.isDisabled ? 'Disabled' : 'Expired'}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="text-center text-muted-foreground">
|
||||
{shareInfo.isDisabled
|
||||
? 'This share link has been disabled by the owner.'
|
||||
: 'This share link has expired and is no longer accessible.'}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="flex flex-1 items-center justify-center bg-background">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
||||
</div>
|
||||
)
|
||||
} else if (!isPasswordValid) {
|
||||
} else if (shareInfoError) {
|
||||
if (shareInfoError.message === 'Unauthorized') {
|
||||
const isPasswordWrong = password !== ''
|
||||
content = (
|
||||
<div className="flex flex-1 items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10">
|
||||
<Lock className="h-6 w-6 text-primary" />
|
||||
</div>
|
||||
<CardTitle>Password Protected</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handlePasswordSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Enter password"
|
||||
value={passwordInput}
|
||||
onChange={(e) => setPasswordInput(e.target.value)}
|
||||
autoFocus
|
||||
/>
|
||||
{isPasswordWrong && (
|
||||
<p className="text-sm font-medium text-destructive">
|
||||
Incorrect password. Please try again.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<Button type="submit" className="w-full">
|
||||
Access Share
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
const isExpired = shareInfoError.message.includes('expired')
|
||||
const isDisabled = shareInfoError.message.includes('disabled')
|
||||
content = (
|
||||
<div className="flex flex-1 items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10">
|
||||
<AlertCircle className="h-6 w-6 text-destructive" />
|
||||
</div>
|
||||
<CardTitle>
|
||||
{isExpired ? 'Share Expired' : isDisabled ? 'Share Disabled' : 'Error'}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="text-center text-muted-foreground">
|
||||
{shareInfoError.message}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
} else if (!shareInfo) {
|
||||
content = (
|
||||
<div className="flex flex-1 items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader className="text-center">
|
||||
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10">
|
||||
<Lock className="h-6 w-6 text-primary" />
|
||||
</div>
|
||||
<CardTitle>Password Protected</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handlePasswordSubmit} className="space-y-4">
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Enter password"
|
||||
value={passwordInput}
|
||||
onChange={(e) => setPasswordInput(e.target.value)}
|
||||
autoFocus
|
||||
/>
|
||||
<Button type="submit" className="w-full">
|
||||
Access Share
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="flex flex-1 items-center justify-center bg-background">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-foreground" />
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
@@ -406,37 +461,39 @@ export function PublicShareManager({
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<FileBrowser
|
||||
teamId=""
|
||||
projectId={shareInfo.projectId}
|
||||
assetId={currentFolderId}
|
||||
folders={folders}
|
||||
files={files}
|
||||
selectedItem={null}
|
||||
selectedIds={selectedIds}
|
||||
onItemSelect={(item, e) => {
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
const next = new Set(selectedIds)
|
||||
if (next.has(item.id!)) next.delete(item.id!)
|
||||
else next.add(item.id!)
|
||||
setSelectedIds(next)
|
||||
} else {
|
||||
setSelectedIds(new Set([item.id!]))
|
||||
}
|
||||
}}
|
||||
onItemDoubleClick={handleItemDoubleClick}
|
||||
onSaveField={() => {}}
|
||||
displayStyle={(shareInfo.viewMode as 'card' | 'list') ?? 'card'}
|
||||
onClearSelection={() => setSelectedIds(new Set())}
|
||||
fetchNextFoldersPage={fetchNextFoldersPage}
|
||||
hasNextFoldersPage={hasNextPageFolders}
|
||||
isFetchingNextFoldersPage={isFetchingNextFoldersPage}
|
||||
fetchNextFilesPage={fetchNextFilesPage}
|
||||
hasNextFilesPage={hasNextPageFiles}
|
||||
isFetchingNextFilesPage={isFetchingNextFilesPage}
|
||||
isShareView={true}
|
||||
isPublic={true}
|
||||
/>
|
||||
currentFolderId && (
|
||||
<FileBrowser
|
||||
teamId=""
|
||||
projectId={shareInfo.projectId}
|
||||
assetId={currentFolderId}
|
||||
folders={folders}
|
||||
files={files}
|
||||
selectedItem={null}
|
||||
selectedIds={selectedIds}
|
||||
onItemSelect={(item, e) => {
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
const next = new Set(selectedIds)
|
||||
if (next.has(item.id!)) next.delete(item.id!)
|
||||
else next.add(item.id!)
|
||||
setSelectedIds(next)
|
||||
} else {
|
||||
setSelectedIds(new Set([item.id!]))
|
||||
}
|
||||
}}
|
||||
onItemDoubleClick={handleItemDoubleClick}
|
||||
onSaveField={() => {}}
|
||||
displayStyle={(shareInfo.viewMode as 'card' | 'list') ?? 'card'}
|
||||
onClearSelection={() => setSelectedIds(new Set())}
|
||||
fetchNextFoldersPage={fetchNextFoldersPage}
|
||||
hasNextFoldersPage={hasNextPageFolders}
|
||||
isFetchingNextFoldersPage={isFetchingNextFoldersPage}
|
||||
fetchNextFilesPage={fetchNextFilesPage}
|
||||
hasNextFilesPage={hasNextPageFiles}
|
||||
isFetchingNextFilesPage={isFetchingNextFilesPage}
|
||||
isShareView={true}
|
||||
isPublic={true}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
||||
{!isRightSidebarCollapsed && (
|
||||
@@ -457,7 +514,7 @@ export function PublicShareManager({
|
||||
publicFields={publicFields}
|
||||
onCommentSelect={handleCommentSelect}
|
||||
isPublic={true}
|
||||
shareId={shareInfo.id}
|
||||
shareId={shareId}
|
||||
currentTime={currentTime}
|
||||
onTyping={() => {
|
||||
if (videoRef.current) {
|
||||
|
||||
@@ -45,10 +45,14 @@ export function ShareSettingsSidebar({
|
||||
onSortOrderChange,
|
||||
}: ShareSettingsSidebarProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const [password, setPassword] = useState('')
|
||||
const [password, setPassword] = useState(shareLink.password || '')
|
||||
const [expireAt, setExpireAt] = useState<Date | undefined>(
|
||||
shareLink.expireAt ? new Date(shareLink.expireAt) : undefined,
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
setPassword(shareLink.password || '')
|
||||
}, [shareLink.password])
|
||||
const [isPasswordEnabled, setIsPasswordEnabled] = useState(shareLink.hasPassword)
|
||||
const [isExpireEnabled, setIsExpireEnabled] = useState(!!shareLink.expireAt)
|
||||
|
||||
@@ -146,10 +150,10 @@ export function ShareSettingsSidebar({
|
||||
{isPasswordEnabled && (
|
||||
<div className="flex gap-2 animate-in fade-in slide-in-from-top-1 duration-200">
|
||||
<Input
|
||||
type="password"
|
||||
type="text"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder={shareLink.hasPassword ? '••••••••' : 'Set password'}
|
||||
placeholder="Enter password"
|
||||
className="text-xs"
|
||||
/>
|
||||
<Button size="sm" onClick={() => updateShare({ password })}>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/webui",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./index.html",
|
||||
|
||||
@@ -1,43 +1,9 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute, Outlet } from '@tanstack/react-router'
|
||||
|
||||
function ShareLayout() {
|
||||
const { shareId } = Route.useParams()
|
||||
|
||||
const {
|
||||
data: shareInfo,
|
||||
isLoading,
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (isLoading) return <ProjectFolderSkeleton />
|
||||
|
||||
if (error || !shareInfo)
|
||||
return (
|
||||
<div className="flex h-screen items-center justify-center text-destructive">
|
||||
Share not found or inaccessible.
|
||||
</div>
|
||||
)
|
||||
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId')({
|
||||
component: ShareLayout,
|
||||
beforeLoad: ({ params: { shareId } }) => {
|
||||
return {
|
||||
password: localStorage.getItem(`share_pwd_${shareId}`) || '',
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,36 +1,11 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
function PublicShareFilePage() {
|
||||
const { shareId, fileId } = Route.useParams()
|
||||
const { start } = Route.useSearch()
|
||||
|
||||
const { data: shareInfo } = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (!shareInfo) return null
|
||||
|
||||
return (
|
||||
<PublicShareManager
|
||||
shareInfo={{
|
||||
...shareInfo,
|
||||
expireAt: shareInfo.expireAt ?? null,
|
||||
isDisabled: shareInfo.isDisabled ?? false,
|
||||
}}
|
||||
initialFileId={fileId}
|
||||
startTime={start}
|
||||
/>
|
||||
)
|
||||
return <PublicShareManager shareId={shareId} initialFileId={fileId} startTime={start} />
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId/files/$fileId')({
|
||||
|
||||
@@ -1,34 +1,10 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
function PublicShareFolderPage() {
|
||||
const { shareId, folderId } = Route.useParams()
|
||||
|
||||
const { data: shareInfo } = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (!shareInfo) return null
|
||||
|
||||
return (
|
||||
<PublicShareManager
|
||||
shareInfo={{
|
||||
...shareInfo,
|
||||
expireAt: shareInfo.expireAt ?? null,
|
||||
isDisabled: shareInfo.isDisabled ?? false,
|
||||
}}
|
||||
initialFolderId={folderId}
|
||||
/>
|
||||
)
|
||||
return <PublicShareManager shareId={shareId} initialFolderId={folderId} />
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId/folders/$folderId')({
|
||||
|
||||
@@ -1,34 +1,10 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { PublicShareManager } from '@/ui/components/public-share-manager'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
|
||||
function PublicShareIndexPage() {
|
||||
const { shareId } = Route.useParams()
|
||||
|
||||
const { data: shareInfo } = useQuery({
|
||||
queryKey: ['share-info', shareId],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.shares[':shareId'].info.$get({
|
||||
param: { shareId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch share info')
|
||||
return await res.json()
|
||||
},
|
||||
})
|
||||
|
||||
if (!shareInfo) return null
|
||||
|
||||
return (
|
||||
<PublicShareManager
|
||||
shareInfo={{
|
||||
...shareInfo,
|
||||
expireAt: shareInfo.expireAt ?? null,
|
||||
isDisabled: shareInfo.isDisabled ?? false,
|
||||
}}
|
||||
initialFolderId={shareInfo.rootFolderId}
|
||||
/>
|
||||
)
|
||||
return <PublicShareManager shareId={shareId} />
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/share/$shareId/')({
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const APP_VERSION = '0.0.11'
|
||||
export const APP_VERSION = '0.1.2'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/workflow-core",
|
||||
"version": "0.0.11",
|
||||
"version": "0.1.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
# Check if /app/data exists and is not owned by the bun user (UID 1000)
|
||||
if [ -d "/app/data" ]; then
|
||||
if [ "$(stat -c '%u' /app/data)" != "1000" ]; then
|
||||
echo "Correcting permissions on /app/data..."
|
||||
chown -R bun:bun /app/data
|
||||
fi
|
||||
fi
|
||||
# Run the CMD as the bun user
|
||||
exec gosu bun "$@"
|
||||
else
|
||||
# Run the CMD directly if already running as non-root
|
||||
exec "$@"
|
||||
fi
|
||||
Reference in New Issue
Block a user