diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 8426788..5f11610 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -61,13 +61,14 @@ jobs: $SUDO useradd --system --home "$DATA_ROOT" --shell /usr/sbin/nologin "$SERVICE_USER" fi - $SUDO mkdir -p "$APP_ROOT/releases" "$APP_ROOT/bin" "$DATA_ROOT/projects" + $SUDO mkdir -p "$APP_ROOT/releases" "$APP_ROOT/bin" "$DATA_ROOT/projects" "$DATA_ROOT/image-projects" $SUDO install -m 0755 "$(command -v node)" "$APP_ROOT/bin/node" $SUDO mkdir -p "$RELEASE_DIR/.next" "$RELEASE_DIR/data" $SUDO cp -a .next/standalone/. "$RELEASE_DIR/" $SUDO cp -a .next/static "$RELEASE_DIR/.next/static" $SUDO cp -a templates vendor "$RELEASE_DIR/" $SUDO ln -sfn "$DATA_ROOT/projects" "$RELEASE_DIR/data/projects" + $SUDO ln -sfn "$DATA_ROOT/image-projects" "$RELEASE_DIR/data/image-projects" $SUDO chown -R root:root "$APP_ROOT" $SUDO chown -R "$SERVICE_USER:$SERVICE_USER" "$DATA_ROOT" $SUDO ln -sfn "$RELEASE_DIR" "$APP_ROOT/current" diff --git a/app/api/image-projects/[id]/images/[file]/route.ts b/app/api/image-projects/[id]/images/[file]/route.ts new file mode 100644 index 0000000..843f401 --- /dev/null +++ b/app/api/image-projects/[id]/images/[file]/route.ts @@ -0,0 +1,14 @@ +import { NextResponse } from "next/server"; +import { readImageProjectFile } from "../../../../../../lib/image-projects"; +import { errorResponse } from "../../../../../../lib/http"; + +export const runtime = "nodejs"; +type Context = { params: Promise<{ id: string; file: string }> }; + +export async function GET(_: Request, context: Context) { + try { + const { id, file } = await context.params; + const image = await readImageProjectFile(id, file); + return new NextResponse(image.data, { headers: { "Content-Type": image.mimeType, "Cache-Control": "private, max-age=3600" } }); + } catch (error) { return errorResponse(error); } +} diff --git a/app/api/image-projects/[id]/images/route.ts b/app/api/image-projects/[id]/images/route.ts new file mode 100644 index 0000000..f231988 --- /dev/null +++ b/app/api/image-projects/[id]/images/route.ts @@ -0,0 +1,14 @@ +import { NextResponse } from "next/server"; +import { addImagesToProject } from "../../../../../lib/image-projects"; +import { errorResponse } from "../../../../../lib/http"; + +export const runtime = "nodejs"; +type Context = { params: Promise<{ id: string }> }; + +export async function POST(request: Request, context: Context) { + try { + const form = await request.formData(); + const files = form.getAll("images").filter((item): item is File => item instanceof File); + return NextResponse.json({ project: await addImagesToProject((await context.params).id, files) }); + } catch (error) { return errorResponse(error); } +} diff --git a/app/api/image-projects/[id]/route.ts b/app/api/image-projects/[id]/route.ts new file mode 100644 index 0000000..6dc97d4 --- /dev/null +++ b/app/api/image-projects/[id]/route.ts @@ -0,0 +1,16 @@ +import { NextResponse } from "next/server"; +import { getImageProject, updateImageProject } from "../../../../lib/image-projects"; +import { errorResponse } from "../../../../lib/http"; + +export const runtime = "nodejs"; +type Context = { params: Promise<{ id: string }> }; + +export async function GET(_: Request, context: Context) { + try { return NextResponse.json({ project: await getImageProject((await context.params).id) }); } + catch (error) { return errorResponse(error); } +} + +export async function PUT(request: Request, context: Context) { + try { return NextResponse.json({ project: await updateImageProject((await context.params).id, await request.json()) }); } + catch (error) { return errorResponse(error); } +} diff --git a/app/api/image-projects/route.ts b/app/api/image-projects/route.ts new file mode 100644 index 0000000..3693f4b --- /dev/null +++ b/app/api/image-projects/route.ts @@ -0,0 +1,19 @@ +import { NextResponse } from "next/server"; +import { createImageProject, listImageProjects } from "../../../lib/image-projects"; +import { errorResponse } from "../../../lib/http"; + +export const runtime = "nodejs"; + +export async function GET() { + try { return NextResponse.json({ projects: await listImageProjects() }); } + catch (error) { return errorResponse(error); } +} + +export async function POST(request: Request) { + try { + const form = await request.formData(); + const files = form.getAll("images").filter((item): item is File => item instanceof File); + const project = await createImageProject(files, form.get("name")); + return NextResponse.json({ project }, { status: 201 }); + } catch (error) { return errorResponse(error); } +} diff --git a/app/globals.css b/app/globals.css index 5959ea0..0d524f2 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,151 +1,168 @@ -:root { - color-scheme: light; - --red: #ff2442; - --ink: #1f1f1f; - --muted: #8b8b8b; - --sidebar: #f7f7f7; - --panel: #f8f8f8; -} - +:root { color-scheme: light; --red: #ff2442; --red-deep: #e91436; --ink: #18181b; --muted: #85858d; --line: #e8e8eb; --soft: #f5f5f7; } * { box-sizing: border-box; } -html, body { margin: 0; min-width: 1024px; min-height: 100%; background: #fff; color: var(--ink); font-family: Inter, "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; } -button { border: 0; font: inherit; cursor: pointer; } +html, body { margin: 0; min-width: 1024px; min-height: 100%; background: #f6f6f7; color: var(--ink); font-family: Inter, "PingFang SC", "Microsoft YaHei", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; } +button, input, textarea, select { font: inherit; } +button { border: 0; cursor: pointer; } +a { color: inherit; text-decoration: none; } -.creator-shell { min-height: 100vh; background: var(--sidebar); } +/* Kling-inspired project home */ +.kling-shell { min-height: 100vh; background: #f6f6f7; } +.kling-windowbar { position: fixed; z-index: 20; inset: 0 0 auto 0; height: 34px; display: flex; align-items: center; gap: 18px; padding: 0 7px; background: #fff; border-bottom: 1px solid #e5e5e7; } +.kling-windowbar strong { width: 142px; font-size: 13px; } +.kling-windowbar button { width: 30px; height: 30px; display: grid; place-items: center; background: transparent; color: #777; } +.kling-sidebar { position: fixed; z-index: 15; left: 0; top: 34px; bottom: 0; width: 76px; display: flex; flex-direction: column; align-items: center; padding: 15px 7px 10px; background: #fff; border-right: 1px solid #e8e8ea; } +.kling-logo { width: 32px; height: 32px; display: grid; place-items: center; margin-bottom: 18px; border: 2px solid var(--red); border-radius: 13px 13px 13px 5px; color: var(--red); font-size: 17px; font-weight: 900; transform: rotate(-8deg); } +.kling-sidebar nav, .side-footer { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 5px; } +.kling-sidebar nav > i { width: 36px; height: 1px; margin: 3px 0; background: #ececef; } +.side-item { width: 62px; min-height: 55px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border-radius: 10px; background: transparent; color: #74747c; font-size: 10px; } +.side-item.active { background: #fff0f2; color: var(--red); } +.side-item:hover { background: #f4f4f6; } +.side-footer { margin-top: auto; } +.side-avatar { width: 30px; height: 30px; display: grid; place-items: center; margin-top: 7px; border-radius: 50%; background: #34343a; color: #fff; font-size: 10px; } -.creator-header { - position: fixed; - z-index: 10; - inset: 0 0 auto 0; - height: 64px; - display: flex; - align-items: center; - justify-content: space-between; - padding: 0 19px 0 20px; - background: #fff; -} - -.creator-brand { display: flex; align-items: center; gap: 13px; white-space: nowrap; } -.creator-brand strong { font-size: 20px; line-height: 1; font-weight: 600; letter-spacing: -.4px; } -.xiaohongshu-logo { - width: 73px; - height: 31px; - display: grid; - place-items: center; - border-radius: 17px; - background: var(--red); - color: #fff; - font-size: 15px; - font-weight: 800; - letter-spacing: -.5px; -} - -.creator-account { height: 46px; display: flex; align-items: center; gap: 7px; padding: 0 2px 0 10px; background: transparent; color: #242424; font-size: 16px; } -.account-photo { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle at 65% 25%, #f6a45c 0 10%, transparent 11%), linear-gradient(135deg, #302722, #8b5b38 55%, #191919); color: #fff; font-size: 11px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); } -.creator-account svg { color: #a0a0a0; margin-left: 2px; } - -.creator-sidebar { - position: fixed; - z-index: 5; - left: 0; - top: 64px; - bottom: 0; - width: 220px; - padding: 16px 20px 24px; - background: var(--sidebar); -} - -.publish-button { - width: 177px; - height: 44px; - display: flex; - align-items: center; - justify-content: center; - gap: 10px; - border-radius: 24px; - background: var(--red); - color: #fff; - font-size: 15px; - font-weight: 600; - box-shadow: none; -} -.publish-button span { margin: 0 2px; } - -.creator-nav { display: flex; flex-direction: column; gap: 1px; margin-top: 18px; } -.creator-nav-item { - width: 100%; - height: 47px; - display: grid; - grid-template-columns: 25px 1fr 18px; - align-items: center; - padding: 0 13px; - border-radius: 9px; - background: transparent; - color: #898989; - text-align: left; - font-size: 14px; -} -.creator-nav-item span { padding-left: 6px; } -.creator-nav-item > svg:last-child { grid-column: 3; } -.creator-nav-item:hover { background: #ededed; color: #555; } - -.creator-main { - position: fixed; - left: 220px; - right: 0; - top: 64px; - bottom: 0; - overflow-y: auto; - background: #fff; - border-top-left-radius: 20px; -} - -.creator-toolbar { - height: 73px; - display: flex; - align-items: center; - justify-content: space-between; - padding: 0 39px 0 49px; -} -.creator-tabs { height: 100%; display: flex; align-items: center; gap: 17px; } -.creator-tabs button { min-width: 94px; height: 42px; padding: 0 16px; border-radius: 23px; background: transparent; color: #929292; font-size: 16px; font-weight: 600; } -.creator-tabs button.active { background: #f7f7f7; color: #202020; } -.draft-button { height: 40px; display: flex; align-items: center; gap: 7px; padding: 0 18px; border-radius: 22px; background: #f8f8f8; color: #262626; font-size: 14px; } - -.upload-panel { - min-height: 606px; - height: calc(100vh - 199px); - margin: 0 39px 0 34px; - display: grid; - place-items: center; - border-radius: 15px; - background: var(--panel); -} -.upload-center { display: flex; flex-direction: column; align-items: center; transform: translateY(-4px); } -.cloud-upload { height: 103px; display: flex; align-items: center; color: #dfdfdf; } -.cloud-upload svg { fill: #dfdfdf; stroke: #f8f8f8; } -.upload-center p { margin: 10px 0 14px; color: #242424; font-size: 14px; } -.upload-action { min-width: 120px; height: 41px; padding: 0 23px; border-radius: 22px; background: var(--red); color: #fff; font-size: 14px; } -.upload-action:hover, .publish-button:hover { background: #f20f35; } - -.upload-guides { - min-height: 134px; - display: grid; - grid-template-columns: repeat(3, 1fr); - margin: 56px 39px 0 203px; -} -.upload-guides > div { min-height: 112px; padding: 16px 42px; border-left: 1px solid #efefef; } -.upload-guides > div:first-child { border-left: 0; } -.upload-guides strong { display: block; margin-bottom: 10px; font-size: 14px; font-weight: 500; } -.upload-guides p { margin: 0; color: #a0a0a0; font-size: 12px; line-height: 1.8; } - -@media (max-width: 1300px) { - .creator-tabs { gap: 2px; } - .creator-tabs button { min-width: 82px; padding: 0 11px; } - .upload-guides { margin-left: 70px; } -} - -@media (max-height: 800px) { - .upload-panel { min-height: 480px; height: calc(100vh - 185px); } - .upload-guides { margin-top: 34px; } +.kling-main { min-height: 100vh; margin-left: 76px; padding: 17px 24px 48px; background: #f6f6f7; } +.tool-heroes { display: grid; grid-template-columns: 1.22fr .85fr .85fr; gap: 14px; max-width: 1500px; margin: 0 auto; } +.hero-card { position: relative; height: 158px; overflow: hidden; border: 1px solid #e7e7ea; border-radius: 15px; background: #fff; color: var(--ink); text-align: left; box-shadow: 0 1px 1px rgba(0,0,0,.02); } +.hero-card > div:first-child { position: relative; z-index: 2; padding: 40px 20px; } +.hero-card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 21px; font-weight: 700; letter-spacing: -.5px; } +.hero-card h2 > svg:last-child { margin-left: 2px; } +.hero-card p { margin: 0; color: #777780; font-size: 13px; } +.primary-hero { background: linear-gradient(115deg, #fff 0 44%, #fff3f5 66%, #ffd7de); } +.primary-hero h2 b { color: var(--red); font-size: 25px; } +.new-badge { position: absolute; top: 0; right: 0; padding: 4px 11px; border-radius: 0 0 0 10px; background: var(--red); color: white; font-size: 10px; font-weight: 700; } +.hero-wave { position: absolute; inset: 0 0 0 42%; transform: rotate(-8deg); } +.hero-wave i { position: absolute; left: -10%; width: 130%; height: 32px; border-radius: 50%; filter: blur(3px); } +.hero-wave i:nth-child(1) { top: 34px; background: linear-gradient(90deg, transparent, #ffbbc6, #ff2442); transform: rotate(-8deg); } +.hero-wave i:nth-child(2) { top: 76px; background: linear-gradient(90deg, transparent, #ffd4da, #ff7b91); transform: rotate(8deg); } +.hero-wave i:nth-child(3) { top: 116px; background: linear-gradient(90deg, transparent, #ffe8ec, #ffb5c1); transform: rotate(-5deg); } +.image-hero { background: linear-gradient(145deg, #fff, #fafafa 58%, #f1f1f3); } +.batch-hero { background: linear-gradient(135deg, #fff, #f7f7f8 70%, #ffe9ed); } +.stacked-pictures { position: absolute; right: 18px; bottom: -22px; width: 114px; height: 92px; } +.stacked-pictures i { position: absolute; width: 60px; height: 74px; border: 4px solid #fff; border-radius: 5px; background: linear-gradient(150deg, #ff8ca0, #f0d2b8 55%, #777); box-shadow: 0 5px 18px rgba(0,0,0,.12); } +.stacked-pictures i:nth-child(1) { left: 0; top: 12px; transform: rotate(-13deg); } +.stacked-pictures i:nth-child(2) { left: 30px; top: 3px; transform: rotate(4deg); background: linear-gradient(140deg, #ddd, #ff647e); } +.stacked-pictures i:nth-child(3) { right: 0; top: 16px; transform: rotate(13deg); background: linear-gradient(150deg, #333, #ffbd70); } +.batch-art i { position: absolute; right: 22px; bottom: -15px; width: 78px; height: 104px; border-radius: 8px; background: linear-gradient(160deg, #2b2b2f, #f1f1f1); transform: rotate(8deg); } +.batch-art i:last-child { right: -8px; bottom: -3px; background: linear-gradient(150deg, #ff2442, #ff9aaa); transform: rotate(-8deg); } + +.quick-tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; max-width: 1500px; margin: 12px auto 0; } +.quick-tool { height: 79px; display: grid; grid-template-columns: 32px 1fr 20px; align-items: center; gap: 8px; padding: 0 18px; border: 1px solid #e7e7ea; border-radius: 13px; background: #fff; color: #34343a; text-align: left; } +.quick-tool > svg:first-child { color: var(--red); } +.quick-tool div { display: flex; flex-direction: column; gap: 5px; } +.quick-tool strong { font-size: 14px; } +.quick-tool small { color: #96969d; font-size: 11px; white-space: nowrap; } +.quick-tool > svg:last-child { color: #999; transition: transform .2s; } +.quick-tool:hover { border-color: #ffc6cf; box-shadow: 0 8px 24px rgba(255,36,66,.08); } +.quick-tool:hover > svg:last-child { transform: translateX(3px); } + +.project-feed { max-width: 1500px; margin: 57px auto 0; } +.project-toolbar { display: flex; align-items: center; gap: 14px; } +.feed-tabs { display: flex; padding: 3px; border: 1px solid #e0e0e3; border-radius: 9px; background: #fff; } +.feed-tabs button { height: 30px; padding: 0 17px; border-radius: 6px; background: transparent; color: #77777f; font-size: 13px; } +.feed-tabs button.active { background: #efeff1; color: #202024; font-weight: 600; } +.project-toolbar > i { width: 1px; height: 27px; background: #dedee2; } +.project-search { width: 380px; height: 37px; display: flex; align-items: center; margin-left: 8px; border: 1px solid #dcdce0; border-radius: 9px; background: #fff; } +.project-search input { flex: 1; min-width: 0; height: 100%; padding: 0 13px; border: 0; outline: 0; background: transparent; color: #333; } +.project-search svg { margin: 0 12px; color: #999; } +.create-project-button { height: 38px; margin-left: auto; padding: 0 18px; border-radius: 9px; background: var(--red); color: #fff; font-size: 13px; font-weight: 600; } +.project-categories { display: flex; gap: 29px; margin: 13px 0 18px; } +.project-categories button { padding: 0; background: transparent; color: #696971; font-size: 13px; } +.project-categories button.active { color: var(--red); font-weight: 700; } + +.project-masonry { columns: 5 210px; column-gap: 8px; } +.project-tile { display: inline-block; width: 100%; break-inside: avoid; margin-bottom: 15px; overflow: hidden; border-radius: 9px; background: #fff; box-shadow: 0 0 0 1px #e9e9ec; transition: transform .18s, box-shadow .18s; } +.project-tile:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(0,0,0,.09); } +.project-cover { position: relative; min-height: 160px; max-height: 345px; overflow: hidden; background: linear-gradient(140deg, #ececef, #dddde1); } +.project-cover img { width: 100%; height: 100%; display: block; object-fit: cover; } +.project-cover span { position: absolute; right: 8px; bottom: 8px; padding: 3px 7px; border-radius: 10px; background: rgba(20,20,22,.68); color: #fff; font-size: 10px; } +.project-caption { display: flex; flex-direction: column; gap: 4px; padding: 10px 11px 12px; } +.project-caption strong { overflow: hidden; color: #2d2d32; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; } +.project-caption small { color: #9b9ba2; font-size: 10px; } +.project-empty { min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed #dddde1; border-radius: 15px; background: #fff; } +.empty-art { position: relative; width: 130px; height: 90px; margin-bottom: 19px; } +.empty-art span { position: absolute; width: 64px; height: 78px; border: 4px solid #fff; border-radius: 7px; background: linear-gradient(145deg, #ffe0e5, #ff657e); box-shadow: 0 8px 25px rgba(0,0,0,.1); } +.empty-art span:nth-child(1) { left: 8px; top: 8px; transform: rotate(-12deg); } +.empty-art span:nth-child(2) { left: 34px; top: 0; background: linear-gradient(145deg, #f1f1f3, #b8b8bf); } +.empty-art span:nth-child(3) { right: 4px; top: 10px; transform: rotate(12deg); background: linear-gradient(145deg, #ff97a8, #ff2442); } +.project-empty h3 { margin: 0 0 7px; font-size: 16px; } +.project-empty p { margin: 0 0 17px; color: #929299; font-size: 12px; } +.project-empty button { height: 37px; padding: 0 18px; border-radius: 9px; background: var(--red); color: #fff; font-size: 12px; } +.upload-overlay { position: fixed; z-index: 100; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; background: rgba(255,255,255,.9); backdrop-filter: blur(5px); } +.upload-spinner, .editor-spinner { width: 35px; height: 35px; border: 3px solid #ffd2d9; border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; } +.upload-overlay strong { font-size: 15px; } +.upload-overlay small { color: #999; } +.dashboard-toast { position: fixed; z-index: 90; right: 22px; bottom: 22px; display: flex; align-items: center; gap: 16px; padding: 12px 14px; border: 1px solid #e3e3e6; border-radius: 10px; background: #fff; box-shadow: 0 12px 35px rgba(0,0,0,.12); font-size: 12px; } +.dashboard-toast button { background: transparent; color: #999; } + +/* Image project editor */ +.image-editor-shell { height: 100vh; min-width: 1100px; overflow: hidden; display: grid; grid-template: 56px 1fr / 164px minmax(520px, 1fr) 304px; background: #ededf0; } +.editor-topbar { grid-column: 1 / 4; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 15px; padding: 0 14px; border-bottom: 1px solid #e1e1e4; background: #fff; } +.editor-brand { display: flex; align-items: center; min-width: 0; gap: 9px; } +.editor-back { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 7px; color: #555; } +.editor-back:hover { background: #f0f0f2; } +.editor-logo { padding: 5px 9px; border-radius: 13px; background: var(--red); color: #fff; font-size: 11px; font-weight: 800; } +.editor-brand i { width: 1px; height: 20px; background: #ddd; } +.editor-brand input { width: min(330px, 36vw); border: 0; outline: 0; color: #222; font-weight: 600; } +.editor-status { display: flex; align-items: center; gap: 7px; color: #8a8a91; font-size: 11px; } +.status-dot { width: 6px; height: 6px; border-radius: 50%; background: #55b36a; } +.editor-actions { display: flex; justify-content: flex-end; gap: 9px; } +.ghost-control, .save-control { height: 34px; padding: 0 14px; border-radius: 8px; font-size: 12px; } +.ghost-control { border: 1px solid #dddde1; background: #fff; color: #45454a; } +.save-control { background: var(--red); color: #fff; font-weight: 600; } +.save-control:disabled { opacity: .55; } +.editor-filmstrip { grid-row: 2; padding: 13px 11px; overflow-y: auto; border-right: 1px solid #dedee2; background: #f8f8f9; } +.filmstrip-title { display: flex; justify-content: space-between; padding: 0 3px 10px; font-size: 12px; font-weight: 600; } +.filmstrip-title small { color: #999; font-weight: 400; } +.filmstrip-list { display: flex; flex-direction: column; gap: 10px; } +.filmstrip-item { position: relative; width: 100%; height: 118px; padding: 5px; overflow: hidden; border: 2px solid transparent; border-radius: 9px; background: #eeeef0; } +.filmstrip-item.active { border-color: var(--red); background: #fff; } +.filmstrip-item > span { position: absolute; z-index: 2; left: 7px; top: 7px; width: 19px; height: 19px; display: grid; place-items: center; border-radius: 6px; background: rgba(20,20,22,.7); color: #fff; font-size: 9px; } +.filmstrip-item img { width: 100%; height: 100%; display: block; border-radius: 5px; object-fit: cover; } +.filmstrip-add { width: 100%; height: 35px; margin-top: 10px; border: 1px dashed #ccc; border-radius: 8px; background: transparent; color: #888; } +.editor-workspace { position: relative; grid-row: 2; min-width: 0; display: grid; grid-template-rows: 43px 1fr 48px; overflow: hidden; background: #e9e9ec; } +.canvas-toolbar { display: flex; align-items: center; justify-content: center; gap: 6px; border-bottom: 1px solid #dddde1; background: #f8f8f9; } +.canvas-toolbar button { height: 29px; padding: 0 10px; border-radius: 7px; background: transparent; color: #66666d; font-size: 11px; } +.canvas-toolbar button:hover { background: #ececef; } +.canvas-toolbar i { width: 1px; height: 18px; margin: 0 5px; background: #ddd; } +.canvas-toolbar span { margin-right: 5px; color: #86868e; font-size: 10px; } +.canvas-viewport { min-height: 0; display: grid; place-items: center; overflow: hidden; padding: 28px; background-image: radial-gradient(#d0d0d4 .7px, transparent .7px); background-size: 16px 16px; } +.canvas-page { position: relative; height: min(66vh, 680px); max-width: 82%; aspect-ratio: var(--canvas-ratio); overflow: hidden; box-shadow: 0 12px 42px rgba(20,20,24,.18); touch-action: none; user-select: none; } +.canvas-page > img { width: 100%; height: 100%; display: block; transform-origin: center; pointer-events: none; } +.canvas-selection { position: absolute; inset: 0; border: 1px solid rgba(255,36,66,.75); pointer-events: none; } +.handle { position: absolute; width: 7px; height: 7px; border: 1px solid var(--red); background: #fff; } +.handle.nw { left: -4px; top: -4px; }.handle.ne { right: -4px; top: -4px; }.handle.sw { left: -4px; bottom: -4px; }.handle.se { right: -4px; bottom: -4px; } +.editor-pagination { display: flex; align-items: center; justify-content: center; gap: 13px; border-top: 1px solid #dddde1; background: #f7f7f8; } +.editor-pagination button { width: 28px; height: 28px; border-radius: 7px; background: #fff; color: #555; } +.editor-pagination button:disabled { color: #c5c5c8; } +.editor-pagination span { color: #6f6f76; font-size: 11px; } +.editor-inspector { grid-row: 2; overflow-y: auto; border-left: 1px solid #dddde1; background: #fff; } +.inspector-tabs { height: 44px; display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid #e5e5e8; } +.inspector-tabs button { position: relative; background: transparent; color: #929298; font-size: 12px; } +.inspector-tabs button.active { color: #26262a; font-weight: 600; } +.inspector-tabs button.active::after { content: ""; position: absolute; left: 24px; right: 24px; bottom: 0; height: 2px; background: var(--red); } +.inspector-section { padding: 15px 16px 18px; border-bottom: 1px solid #ececef; } +.inspector-section h3 { display: flex; justify-content: space-between; margin: 0 0 14px; font-size: 12px; } +.inspector-section h3 button { background: transparent; color: #aaa; } +.ratio-buttons, .segmented-control { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; } +.ratio-buttons button, .segmented-control button { height: 31px; border: 1px solid #dedee2; border-radius: 7px; background: #fafafa; color: #666; font-size: 11px; } +.ratio-buttons button.active, .segmented-control button.active { border-color: #ff9bab; background: #fff3f5; color: var(--red); } +.segmented-control { grid-template-columns: 1fr 1fr; margin-bottom: 14px; } +.color-field { display: grid; grid-template-columns: 1fr 27px 68px; align-items: center; gap: 8px; margin-top: 13px; color: #64646b; font-size: 11px; } +.color-field input { width: 27px; height: 27px; padding: 0; border: 0; background: none; } +.color-field code { padding: 5px; border: 1px solid #e0e0e3; border-radius: 5px; color: #777; font-size: 10px; text-align: center; } +.range-field { display: block; margin-top: 12px; } +.range-field > div { display: flex; justify-content: space-between; margin-bottom: 7px; color: #66666d; font-size: 11px; } +.range-field code { color: #999; font-size: 10px; } +.range-field input { width: 100%; accent-color: var(--red); } +.editor-loading { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: #f6f6f7; color: #777; } +.editor-loading a { color: var(--red); font-size: 12px; } +@keyframes spin { to { transform: rotate(360deg); } } + +@media (max-width: 1200px) { + .tool-heroes { grid-template-columns: 1.15fr 1fr; } + .batch-hero { display: none; } + .quick-tools { grid-template-columns: repeat(4, 1fr); } + .quick-tool:last-child { display: none; } + .project-search { width: 270px; } + .image-editor-shell { grid-template-columns: 140px minmax(480px, 1fr) 280px; } } diff --git a/app/layout.tsx b/app/layout.tsx index 39fcdcd..1b23240 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -2,8 +2,8 @@ import type { Metadata } from "next"; import "./globals.css"; export const metadata: Metadata = { - title: "创作服务平台", - description: "内容创作服务平台。", + title: "Rednote Studio", + description: "小红书图文项目创作与编辑工具。", }; export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) { diff --git a/app/projects/[id]/editor/page.tsx b/app/projects/[id]/editor/page.tsx new file mode 100644 index 0000000..5bf6be5 --- /dev/null +++ b/app/projects/[id]/editor/page.tsx @@ -0,0 +1,5 @@ +import ImageEditor from "../../../../components/ImageEditor"; + +export default async function ImageProjectEditor({ params }: { params: Promise<{ id: string }> }) { + return ; +} diff --git a/components/ImageEditor.tsx b/components/ImageEditor.tsx new file mode 100644 index 0000000..5eb6d6f --- /dev/null +++ b/components/ImageEditor.tsx @@ -0,0 +1,163 @@ +"use client"; + +import { useCallback, useEffect, useRef, useState } from "react"; +import type { CSSProperties, PointerEvent as ReactPointerEvent } from "react"; + +type Settings = { + fit: "contain" | "cover"; + scale: number; + offsetX: number; + offsetY: number; + rotation: number; + brightness: number; + contrast: number; + saturation: number; + borderRadius: number; +}; + +type Slide = { id: string; fileName: string; originalName: string; mimeType: string; settings: Settings }; +type Project = { id: string; name: string; canvas: { width: number; height: number; background: string }; slides: Slide[]; createdAt: string; updatedAt: string }; + +async function readJson(response: Response): Promise { + const data = await response.json(); + if (!response.ok) throw new Error(data.error || `请求失败:${response.status}`); + return data; +} + +function imageUrl(projectId: string, fileName: string) { return `/api/image-projects/${projectId}/images/${fileName}`; } + +export default function ImageEditor({ projectId }: { projectId: string }) { + const [project, setProject] = useState(null); + const [selectedId, setSelectedId] = useState(""); + const [busy, setBusy] = useState(""); + const [message, setMessage] = useState("正在载入项目…"); + const fileInput = useRef(null); + const drag = useRef<{ x: number; y: number; offsetX: number; offsetY: number } | null>(null); + + const load = useCallback(async () => { + try { + const data = await readJson<{ project: Project }>(await fetch(`/api/image-projects/${projectId}`)); + setProject(data.project); + setSelectedId((current) => current || data.project.slides[0]?.id || ""); + setMessage("项目已载入"); + } catch (error) { setMessage((error as Error).message); } + }, [projectId]); + + useEffect(() => { void load(); }, [load]); + const selected = project?.slides.find((slide) => slide.id === selectedId) || project?.slides[0]; + + function updateSettings(patch: Partial) { + if (!project || !selected) return; + setProject({ ...project, slides: project.slides.map((slide) => slide.id === selected.id ? { ...slide, settings: { ...slide.settings, ...patch } } : slide) }); + } + + async function save() { + if (!project) return; + setBusy("save"); + try { + const data = await readJson<{ project: Project }>(await fetch(`/api/image-projects/${project.id}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(project) })); + setProject(data.project); + setMessage("所有修改已保存"); + } catch (error) { setMessage((error as Error).message); } + finally { setBusy(""); } + } + + async function addImages(files: FileList | null) { + if (!project || !files?.length) return; + setBusy("upload"); + try { + const form = new FormData(); + Array.from(files).forEach((file) => form.append("images", file)); + const data = await readJson<{ project: Project }>(await fetch(`/api/image-projects/${project.id}/images`, { method: "POST", body: form })); + setProject(data.project); + setSelectedId(data.project.slides.at(-1)?.id || selectedId); + setMessage(`已添加 ${files.length} 张图片`); + } catch (error) { setMessage((error as Error).message); } + finally { setBusy(""); if (fileInput.current) fileInput.current.value = ""; } + } + + function setCanvas(width: number, height: number) { + if (project) setProject({ ...project, canvas: { ...project.canvas, width, height } }); + } + + function onPointerDown(event: ReactPointerEvent) { + if (!selected) return; + event.currentTarget.setPointerCapture(event.pointerId); + drag.current = { x: event.clientX, y: event.clientY, offsetX: selected.settings.offsetX, offsetY: selected.settings.offsetY }; + } + + function onPointerMove(event: ReactPointerEvent) { + if (!drag.current || !selected) return; + const rect = event.currentTarget.getBoundingClientRect(); + updateSettings({ offsetX: Math.max(-100, Math.min(100, drag.current.offsetX + (event.clientX - drag.current.x) / rect.width * 100)), offsetY: Math.max(-100, Math.min(100, drag.current.offsetY + (event.clientY - drag.current.y) / rect.height * 100)) }); + } + + function onPointerUp(event: ReactPointerEvent) { + drag.current = null; + event.currentTarget.releasePointerCapture(event.pointerId); + } + + if (!project) return

{message}

返回首页
; + if (!selected) return

项目中没有图片

返回首页
; + + const style = { + transform: `translate(${selected.settings.offsetX}%, ${selected.settings.offsetY}%) scale(${selected.settings.scale / 100}) rotate(${selected.settings.rotation}deg)`, + filter: `brightness(${selected.settings.brightness}%) contrast(${selected.settings.contrast}%) saturate(${selected.settings.saturation}%)`, + objectFit: selected.settings.fit, + borderRadius: `${selected.settings.borderRadius}px`, + } as CSSProperties; + const ratioStyle = { "--canvas-ratio": `${project.canvas.width} / ${project.canvas.height}`, background: project.canvas.background } as CSSProperties; + + return
+
+
←小红书 setProject({ ...project, name: event.target.value })} />
+
{message}
+
+ void addImages(event.target.files)} /> +
+ + + +
+
{project.canvas.width} × {project.canvas.height}
+
+
+ {selected.originalName} +
+
+
+
{project.slides.findIndex((item) => item.id === selected.id) + 1} / {project.slides.length}
+
+ + +
; +} + +function InspectorSection({ title, children }: { title: string; children: React.ReactNode }) { + return

{title}

{children}
; +} + +function Range({ label, value, min, max, suffix, onChange }: { label: string; value: number; min: number; max: number; suffix: string; onChange: (value: number) => void }) { + return ; +} diff --git a/components/Studio.tsx b/components/Studio.tsx index 99caa3c..d51040d 100644 --- a/components/Studio.tsx +++ b/components/Studio.tsx @@ -1,76 +1,121 @@ "use client"; -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; -type IconName = "home" | "note" | "code" | "chart" | "flag" | "bulb" | "school" | "book" | "draft" | "plus" | "chevron" | "upload"; +type IconName = "home" | "create" | "assets" | "projects" | "canvas" | "tools" | "bell" | "api" | "plus" | "image" | "layers" | "magic" | "resize" | "grid" | "search" | "arrow"; +type Project = { id: string; name: string; slides: Array<{ fileName: string }>; canvas: { width: number; height: number }; updatedAt: string }; const paths: Record = { - home: <>, - note: <>, - code: <>, - chart: <>, - flag: <>, - bulb: <>, - school: <>, - book: <>, - draft: <>, - plus: <>, - chevron: , - upload: <>, + home: , + create: <>, + assets: <>, + projects: <>, + canvas: <>, + tools: <>, + bell: <>, + api: <>, + plus: , + image: <>, + layers: <>, + magic: <>, + resize: <>, + grid: <>, + search: <>, + arrow: , }; -function Icon({ name, size = 19, strokeWidth = 1.55 }: { name: IconName; size?: number; strokeWidth?: number }) { - return ; +function Icon({ name, size = 20 }: { name: IconName; size?: number }) { + return ; } -const navItems: Array<{ icon: IconName; label: string; expandable?: boolean }> = [ - { icon: "home", label: "首页" }, - { icon: "note", label: "笔记管理" }, - { icon: "code", label: "Builder hub", expandable: true }, - { icon: "chart", label: "数据看板", expandable: true }, - { icon: "flag", label: "活动中心" }, - { icon: "bulb", label: "笔记灵感" }, - { icon: "school", label: "创作学院" }, - { icon: "book", label: "创作百科" }, -]; - -const tabs = ["上传视频", "上传图文", "写长文", "发播客"]; +function imageUrl(project: Project) { return project.slides[0] ? `/api/image-projects/${project.id}/images/${project.slides[0].fileName}` : ""; } export default function Studio() { - const [activeTab, setActiveTab] = useState("上传视频"); + const [projects, setProjects] = useState([]); + const [filter, setFilter] = useState("项目"); + const [query, setQuery] = useState(""); + const [uploading, setUploading] = useState(false); + const [message, setMessage] = useState(""); + const input = useRef(null); - return
-
-
小红书创作服务平台
- -
+ useEffect(() => { + fetch("/api/image-projects").then(async (response) => { + const data = await response.json(); + if (!response.ok) throw new Error(data.error || "项目载入失败"); + setProjects(data.projects || []); + }).catch((error) => setMessage((error as Error).message)); + }, []); -