Compare commits

...
23 Commits
Author SHA1 Message Date
yiling 3737418ec3 Release v0.1.2 2026-06-25 19:43:07 +08:00
Yiling-J 6d47ea7466 Update AWS_ENDPOINT_URL_S3 explanation in README
Clarified the default value for AWS_ENDPOINT_URL_S3 and its usage with custom host/port.
2026-06-25 19:15:11 +08:00
Yiling-J 84d96ff83a Revise README for environment variable setup
Updated environment variable configuration instructions for clarity and added optional settings for S3-compatible storage.
2026-06-25 19:11:39 +08:00
Yiling-J 6e985aed61 Merge pull request #155 from shumaiOne/refactor/s3-endpoint
refactor(s3): remove automatic port appending to AWS_ENDPOINT_URL_S3
2026-06-25 18:56:49 +08:00
yiling 8347a9ca15 docs(docker): document SHUMAI_SERVER_PORT and update local docker-compose env 2026-06-25 18:50:29 +08:00
yiling ab9b33320d docs(s3): document SHUMAI_SERVER_PORT and S3 endpoint port configurations 2026-06-25 18:48:23 +08:00
yiling efd6163238 refactor(s3): remove automatic port appending to AWS_ENDPOINT_URL_S3 2026-06-25 18:46:14 +08:00
yiling 0e4bdec0e3 Release v0.1.1 2026-06-23 10:32:41 +08:00
yiling 0eb03b16a4 chore(docker): add AWS_ENDPOINT_URL_S3 to local docker-compose 2026-06-23 10:27:18 +08:00
Yiling-J b216773044 Merge pull request #151 from shumaiOne/docker/entrypoint-privilege-dropping
feat(docker): add root entrypoint with privilege dropping for data volumes
2026-06-23 10:09:57 +08:00
yiling 92801ba14a fix(core): make version stack sort index lookup deterministic
When creating a version stack, the sortIndex was previously extracted
by taking files[0] from the database query result. Because findMany
without orderBy is non-deterministic, this resulted in flakiness
where the sortIndex would sometimes be null (from file2) instead of
'abc' (from file1), causing tests to fail.

We now look up the first file specifically based on the ordered
fileIds array parameter.
2026-06-23 10:02:01 +08:00
yiling 661e836f06 fix(docker): support non-root/restricted container environments in entrypoint
Checks if the container is running as root (UID 0) before executing
chown and gosu. If running directly as a non-root user (e.g. in hardened
environments like Kubernetes runAsNonRoot or via docker run --user),
it directly execs the command, preventing EACCES and permission errors.
2026-06-23 09:56:31 +08:00
yiling fb5c7ecabe chore(docker): ignore dist and data directories in .dockerignore
This adds the `dist` and `data` folders to `.dockerignore` to prevent
them from being transferred as part of the Docker build context.
This reduces the build context size by over 1.5GB+, making the build
much faster.
2026-06-23 09:53:00 +08:00
yiling a390643458 feat(docker): add root entrypoint with privilege dropping for data volumes
This updates the Dockerfile and adds a scripts/docker-entrypoint.sh script.
Under native Linux (like Debian), when docker-compose mounts a host folder
as a volume (e.g. `./data:/app/data`), and the folder doesn't exist, the
docker daemon creates the folder as root-owned (`root:root`).

Because the container runs as a non-root user `bun`, it gets permission
denied (`EACCES`) when trying to write to the data directory.

To resolve this in a beginner-friendly way without manual host-side
permissions updates:
1. The runner stage now installs `gosu`.
2. At the end of the Dockerfile, the user switches back to `root` so the
   container launches as root.
3. On launch, the entrypoint script executes. Since it runs as root, it
   automatically changes ownership of `/app/data` to `bun:bun`.
4. The entrypoint script then uses `gosu` to drop privileges and launch the
   actual server processes as the non-root `bun` user.
2026-06-23 09:46:56 +08:00
yiling 9325c71b51 Release v0.1.0 2026-06-22 21:45:39 +08:00
Yiling-J 2f746d3ce8 Merge pull request #150 from shumaiOne/feat/secure-share-info
feat(share): secure share info API and fix wrong password feedback
2026-06-22 20:53:56 +08:00
yiling bdceda4cb6 refactor(share): use custom strongly-typed error classes 2026-06-22 20:48:47 +08:00
yiling df6e392bf6 feat(share): expose raw password on settings page 2026-06-22 20:32:46 +08:00
yiling 48b2047a84 feat(share): secure share info API and fix wrong password feedback 2026-06-22 20:21:44 +08:00
yiling 2b360b2b2c chore(docker): update shumai image tag to latest 2026-06-22 15:52:00 +08:00
Yiling-J 5d19e6ddfa Merge pull request #149 from shumaiOne/fix-sidebar-overflow
fix(webui): truncate long folder, collection, and share link names in sidebar
2026-06-22 15:46:18 +08:00
yiling 5e70b6f3ee docs: add note blocks for running binaries under Bun runtime 2026-06-22 15:39:47 +08:00
yiling 8eab02ab28 fix(webui): truncate long folder, collection, and share link names in sidebar 2026-06-22 15:22:44 +08:00
39 changed files with 489 additions and 324 deletions
+2
View File
@@ -1,4 +1,6 @@
node_modules
dist
data
Dockerfile*
docker-compose*
.dockerignore
+8
View File
@@ -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"]
+29 -6
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent-app",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"bin": {
+3
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/cli",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode-app",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/web-app",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"dependencies": {
+5 -1
View File
@@ -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=
+22 -10
View File
@@ -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`.
---
+3
View File
@@ -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`).
+13 -1
View File
@@ -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
View File
@@ -1,6 +1,6 @@
{
"name": "shumai",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"repository": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/api",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+31 -41
View File
@@ -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)
}
},
)
+60
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/core",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+35
View File
@@ -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')
})
})
})
+2 -2
View File
@@ -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)
+31
View File
@@ -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)
}
}
+13 -6
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/db",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/dtos",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/tableprinter",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+15 -12
View File
@@ -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}>
+173 -116
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/webui",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./index.html",
-34
View File
@@ -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 -25
View File
@@ -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
View File
@@ -1 +1 @@
export const APP_VERSION = '0.0.11'
export const APP_VERSION = '0.1.2'
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/workflow-core",
"version": "0.0.11",
"version": "0.1.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+17
View File
@@ -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