@2kog/kacha 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/init-project.js +14 -23
- package/package.json +1 -1
- package/server/asset-watch.js +12 -3
- package/server/image-assets.js +2 -2
- package/server/index.js +4 -0
- package/server/project-scripts.js +93 -0
- package/server/project-settings.js +101 -12
- package/server/project-storyboard.js +89 -0
- package/src/assets/css/workbench.css +14 -15
- package/src/components/AssetStoryEditor.vue +15 -9
- package/src/components/JimengPromptPreview.vue +69 -0
- package/src/components/ProjectMarkdown.vue +2 -1
- package/src/components/ScriptVersionDiff.vue +96 -0
- package/src/components/StoryboardDocument.vue +99 -0
- package/src/i18n/en.json +42 -7
- package/src/layouts/WorkbenchLayout.vue +35 -46
- package/src/router/index.js +8 -2
- package/src/service/project-markdown.js +13 -1
- package/src/service/resume.js +18 -0
- package/src/views/assets/CharacterAssets.vue +39 -5
- package/src/views/home/ProjectHome.vue +119 -0
- package/src/views/scripts/ProjectScripts.vue +272 -0
- package/src/views/scripts/ProjectStoryboard.vue +126 -0
- package/src/views/settings/ProjectSettings.vue +62 -20
- package/templates/project/.lfsconfig +2 -0
- package/templates/project/AGENTS.md +116 -15
- package/templates/project/README.md +51 -7
- package/templates/project/assets/audio/.gitkeep +0 -0
- package/templates/project/assets/characters/.gitkeep +0 -0
- package/templates/project/assets/other/.gitkeep +0 -0
- package/templates/project/assets/props/.gitkeep +0 -0
- package/templates/project/assets/scenes/.gitkeep +0 -0
- package/templates/project/config/.gitkeep +0 -0
- package/templates/project/docs/art//345/234/272/346/231/257/344/270/216/347/251/272/351/227/264.md +3 -0
- package/templates/project/docs/art//350/247/222/350/211/262/347/276/216/346/234/257.md +3 -0
- package/templates/project/docs/art//351/201/223/345/205/267/347/276/216/346/234/257.md +3 -0
- package/templates/project/docs/other//350/241/245/345/205/205/350/257/264/346/230/216.md +7 -0
- package/templates/project/docs/story//344/270/226/347/225/214/350/247/202/344/270/216/350/247/222/350/211/262.md +3 -0
- package/templates/project/env.template +5 -0
- package/templates/project/gitignore.template +5 -0
- package/templates/project/package.json +8 -0
- package/templates/project/scripts/.gitkeep +0 -0
- package/templates/project/storyboard/.gitkeep +0 -0
- package/vite.config.js +1 -1
- package/templates/project/assets/audio/README.md +0 -5
- package/templates/project/assets/characters/README.md +0 -5
- package/templates/project/assets/other/README.md +0 -3
- package/templates/project/assets/props/README.md +0 -3
- package/templates/project/assets/scenes/README.md +0 -3
package/bin/init-project.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import { constants } from 'node:fs'
|
|
2
|
-
import { copyFile, lstat, mkdir, readdir, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { copyFile, lstat, mkdir, readdir, readFile, writeFile } from 'node:fs/promises'
|
|
3
3
|
import { basename, join } from 'node:path'
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
|
|
6
6
|
const templateRoot = fileURLToPath(new URL('../templates/project/', import.meta.url))
|
|
7
7
|
|
|
8
|
-
const gitignore = `.DS_Store
|
|
9
|
-
tmp/
|
|
10
|
-
node_modules/
|
|
11
|
-
.env
|
|
12
|
-
.env.*
|
|
13
|
-
.kacha/oss-sync/
|
|
14
|
-
.kacha/lfs-transfer/
|
|
15
|
-
`
|
|
16
|
-
|
|
17
|
-
const envTemplate = `OSS_ENDPOINT=
|
|
18
|
-
OSS_BUCKET=
|
|
19
|
-
OSS_PREFIX=
|
|
20
|
-
OSS_ACCESS_KEY_ID=
|
|
21
|
-
OSS_ACCESS_KEY_SECRET=
|
|
22
|
-
`
|
|
23
|
-
|
|
24
8
|
async function keepExisting(operation) {
|
|
25
9
|
try {
|
|
26
10
|
await operation()
|
|
@@ -31,14 +15,26 @@ async function keepExisting(operation) {
|
|
|
31
15
|
|
|
32
16
|
async function copyTemplates(source, destination) {
|
|
33
17
|
for (const entry of await readdir(source, { withFileTypes: true })) {
|
|
18
|
+
if (entry.name === '.gitkeep') continue
|
|
34
19
|
const from = join(source, entry.name)
|
|
35
|
-
|
|
20
|
+
// npm omits .env and .gitignore, so restore their names during initialization.
|
|
21
|
+
const outputName = source === templateRoot
|
|
22
|
+
? ({ 'env.template': '.env', 'gitignore.template': '.gitignore' }[entry.name] || entry.name)
|
|
23
|
+
: entry.name
|
|
24
|
+
const to = join(destination, outputName)
|
|
36
25
|
if (entry.isDirectory()) {
|
|
37
26
|
await keepExisting(() => mkdir(to))
|
|
38
27
|
if (!(await lstat(to)).isDirectory()) {
|
|
39
28
|
throw new Error(`Expected a directory at ${to}`)
|
|
40
29
|
}
|
|
41
30
|
await copyTemplates(from, to)
|
|
31
|
+
} else if (source === templateRoot && ['.env', '.lfsconfig'].includes(outputName)) {
|
|
32
|
+
let content = await readFile(from, 'utf8')
|
|
33
|
+
if (entry.name === '.lfsconfig') {
|
|
34
|
+
const projectName = encodeURIComponent(basename(destination) || 'project')
|
|
35
|
+
content = content.replace('{{projectName}}', () => projectName)
|
|
36
|
+
}
|
|
37
|
+
await keepExisting(() => writeFile(to, content, { flag: 'wx', mode: outputName === '.env' ? 0o600 : 0o666 }))
|
|
42
38
|
} else {
|
|
43
39
|
await keepExisting(() => copyFile(from, to, constants.COPYFILE_EXCL))
|
|
44
40
|
}
|
|
@@ -47,9 +43,4 @@ async function copyTemplates(source, destination) {
|
|
|
47
43
|
|
|
48
44
|
export async function initProject(projectRoot) {
|
|
49
45
|
await copyTemplates(templateRoot, projectRoot)
|
|
50
|
-
await keepExisting(() => writeFile(join(projectRoot, '.gitignore'), gitignore, { flag: 'wx' }))
|
|
51
|
-
await keepExisting(() => writeFile(join(projectRoot, '.env'), envTemplate, { flag: 'wx', mode: 0o600 }))
|
|
52
|
-
const projectName = encodeURIComponent(basename(projectRoot) || 'project')
|
|
53
|
-
const lfsConfig = `[lfs]\n\turl = https://kacha-lfs.invalid/${projectName}\n`
|
|
54
|
-
await keepExisting(() => writeFile(join(projectRoot, '.lfsconfig'), lfsConfig, { flag: 'wx' }))
|
|
55
46
|
}
|
package/package.json
CHANGED
package/server/asset-watch.js
CHANGED
|
@@ -7,21 +7,30 @@ const roots = Object.fromEntries(['characters', 'scenes', 'props', 'other', 'aud
|
|
|
7
7
|
|
|
8
8
|
roots.settings = path.join(projectRoot, 'docs')
|
|
9
9
|
|
|
10
|
+
roots.scripts = path.join(projectRoot, 'scripts')
|
|
11
|
+
roots.storyboard = path.join(projectRoot, 'storyboard')
|
|
12
|
+
const watched = [...Object.entries(roots), ...['scripts', 'storyboard'].map(kind =>
|
|
13
|
+
[kind, path.join(projectRoot, 'dist', kind)])]
|
|
14
|
+
|
|
10
15
|
export function assetWatch() {
|
|
11
16
|
return {
|
|
12
17
|
name: 'workbench-asset-watch',
|
|
13
18
|
configureServer(server) {
|
|
14
19
|
const pending = new Map()
|
|
15
|
-
|
|
20
|
+
const changes = new Map()
|
|
21
|
+
server.watcher.add(watched.map(([, root]) => root))
|
|
16
22
|
const onChange = (event, file) => {
|
|
17
23
|
if (!['add', 'change', 'unlink', 'addDir', 'unlinkDir'].includes(event)) return
|
|
18
|
-
for (const [kind, root] of
|
|
24
|
+
for (const [kind, root] of watched) {
|
|
19
25
|
const relative = path.relative(root, file)
|
|
20
26
|
if (relative.split(path.sep).some(part => part.startsWith('.')) || path.isAbsolute(relative)) continue
|
|
27
|
+
if (!changes.has(kind)) changes.set(kind, new Set())
|
|
28
|
+
changes.get(kind).add(path.relative(projectRoot, file).split(path.sep).join('/'))
|
|
21
29
|
clearTimeout(pending.get(kind))
|
|
22
30
|
pending.set(kind, setTimeout(() => {
|
|
23
31
|
pending.delete(kind)
|
|
24
|
-
server.ws.send({ type: 'custom', event: 'workbench:' + kind + ':changed', data: {} })
|
|
32
|
+
server.ws.send({ type: 'custom', event: 'workbench:' + kind + ':changed', data: { files: [...changes.get(kind)] } })
|
|
33
|
+
changes.delete(kind)
|
|
25
34
|
}, 150))
|
|
26
35
|
}
|
|
27
36
|
}
|
package/server/image-assets.js
CHANGED
|
@@ -523,7 +523,7 @@ async function readBody(req) {
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
async function
|
|
526
|
+
export async function streamMedia(file, req, res) {
|
|
527
527
|
const { size } = await fs.stat(file)
|
|
528
528
|
res.setHeader('Accept-Ranges', 'bytes')
|
|
529
529
|
const range = req.headers.range
|
|
@@ -578,7 +578,7 @@ export function imageAssets(kind) {
|
|
|
578
578
|
res.setHeader('Content-Type', mime)
|
|
579
579
|
res.setHeader('Cache-Control', 'no-cache')
|
|
580
580
|
if (isAudio) {
|
|
581
|
-
await
|
|
581
|
+
await streamMedia(file, req, res)
|
|
582
582
|
return
|
|
583
583
|
}
|
|
584
584
|
createReadStream(file).on('error', () => res.destroy()).pipe(res)
|
package/server/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { projectStoryboard } from './project-storyboard.js'
|
|
1
2
|
import { assetWatch } from './asset-watch.js'
|
|
2
3
|
import { characterAssets } from './character-assets.js'
|
|
3
4
|
import { imageAssets } from './image-assets.js'
|
|
@@ -6,12 +7,15 @@ import { projectBrand } from './project-brand.js'
|
|
|
6
7
|
import { projectOssSync } from './project-oss-sync.js'
|
|
7
8
|
import { projectStorage } from './project-storage.js'
|
|
8
9
|
import { projectSettings } from './project-settings.js'
|
|
10
|
+
import { projectScripts } from './project-scripts.js'
|
|
9
11
|
|
|
10
12
|
export function workbenchPlugins() {
|
|
11
13
|
return [
|
|
12
14
|
characterAssets(),
|
|
13
15
|
...['scenes', 'props', 'other', 'audio'].map(imageAssets),
|
|
14
16
|
projectSettings(),
|
|
17
|
+
projectScripts(),
|
|
18
|
+
projectStoryboard(),
|
|
15
19
|
projectBrand(),
|
|
16
20
|
projectGlobal(),
|
|
17
21
|
projectStorage(),
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { projectRoot } from './project-paths.js'
|
|
4
|
+
import { streamMedia } from './image-assets.js'
|
|
5
|
+
|
|
6
|
+
const root = path.join(projectRoot, 'scripts')
|
|
7
|
+
const videoRoot = path.join(projectRoot, 'dist', 'scripts')
|
|
8
|
+
const episodeName = /^\d{3}-.+/
|
|
9
|
+
const videoTypes = new Map([
|
|
10
|
+
['.mp4', 'video/mp4'], ['.mov', 'video/quicktime'], ['.webm', 'video/webm'],
|
|
11
|
+
['.m4v', 'video/mp4'], ['.mkv', 'video/x-matroska'],
|
|
12
|
+
])
|
|
13
|
+
|
|
14
|
+
function acceptedDirectory(name) {
|
|
15
|
+
return name === 'opening' || name === 'ending' || episodeName.test(name)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function entries(directory) {
|
|
19
|
+
if (await fs.realpath(directory).catch(() => '') !== directory) return []
|
|
20
|
+
return fs.readdir(directory, { withFileTypes: true })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function compareFiles(a, b) {
|
|
24
|
+
return a.localeCompare(b, undefined, { numeric: true })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function listScripts() {
|
|
28
|
+
const directories = (await entries(root))
|
|
29
|
+
.filter(entry => entry.isDirectory() && acceptedDirectory(entry.name))
|
|
30
|
+
.map(entry => entry.name)
|
|
31
|
+
.sort((a, b) => {
|
|
32
|
+
if (a === 'opening' || b === 'ending') return -1
|
|
33
|
+
if (b === 'opening' || a === 'ending') return 1
|
|
34
|
+
return compareFiles(a, b)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return Promise.all(directories.map(async name => {
|
|
38
|
+
const directory = path.join(root, name)
|
|
39
|
+
const files = (await entries(directory)).filter(entry => entry.isFile()).map(entry => entry.name).sort(compareFiles)
|
|
40
|
+
const archived = (await entries(path.join(directory, 'archive')))
|
|
41
|
+
.filter(entry => entry.isFile()).map(entry => entry.name).sort(compareFiles).reverse()
|
|
42
|
+
const outputs = (await entries(path.join(videoRoot, name))).filter(entry => entry.isFile()).map(entry => entry.name)
|
|
43
|
+
const documents = files.filter(file => /\.(md|markdown)$/i.test(file))
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
documents: documents.includes('index.md')
|
|
47
|
+
? ['index.md', ...documents.filter(file => file !== 'index.md')]
|
|
48
|
+
: documents,
|
|
49
|
+
history: archived.filter(file => /\.(md|markdown)$/i.test(file)),
|
|
50
|
+
videos: [...new Set([...outputs, ...files])].filter(file => videoTypes.has(path.extname(file).toLowerCase())).sort(compareFiles),
|
|
51
|
+
}
|
|
52
|
+
}))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function projectScripts() {
|
|
56
|
+
return {
|
|
57
|
+
name: 'workbench-project-scripts',
|
|
58
|
+
configureServer(server) {
|
|
59
|
+
server.middlewares.use(async (req, res, next) => {
|
|
60
|
+
const url = new URL(req.url, 'http://localhost')
|
|
61
|
+
if (url.pathname !== '/api/scripts') return next()
|
|
62
|
+
if (req.method !== 'GET') {
|
|
63
|
+
res.statusCode = 405
|
|
64
|
+
return res.end()
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const video = url.searchParams.get('video')
|
|
68
|
+
if (video === null) {
|
|
69
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
70
|
+
return res.end(JSON.stringify(await listScripts()))
|
|
71
|
+
}
|
|
72
|
+
const [directory, filename, ...rest] = video.split('/')
|
|
73
|
+
const type = videoTypes.get(path.extname(filename || '').toLowerCase())
|
|
74
|
+
if (acceptedDirectory(directory) && type && !rest.length && path.basename(filename) === filename) {
|
|
75
|
+
for (const base of [videoRoot, root]) {
|
|
76
|
+
const file = path.join(base, directory, filename)
|
|
77
|
+
if (await fs.realpath(file).catch(() => '') === file && (await fs.stat(file)).isFile()) {
|
|
78
|
+
res.setHeader('Content-Type', type)
|
|
79
|
+
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
80
|
+
return await streamMedia(file, req, res)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
res.statusCode = 404
|
|
85
|
+
return res.end()
|
|
86
|
+
} catch (cause) {
|
|
87
|
+
res.statusCode = cause.code === 'ENOENT' ? 404 : 500
|
|
88
|
+
return res.end()
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -1,18 +1,61 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises'
|
|
2
|
+
import { copyFileSync, constants, mkdirSync, readdirSync, realpathSync, readFileSync, writeFileSync, renameSync, rmSync } from 'node:fs'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
2
4
|
import path from 'node:path'
|
|
5
|
+
import { listStoryboard } from './project-storyboard.js'
|
|
6
|
+
import { listScripts } from './project-scripts.js'
|
|
3
7
|
import { projectRoot } from './project-paths.js'
|
|
4
8
|
|
|
5
9
|
const root = projectRoot
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
async function listDocuments() {
|
|
11
|
+
const documents = []
|
|
12
|
+
for (const [folder, group] of [['story', '故事设定'], ['art', '美术设定'], ['other', '其它设定']]) {
|
|
13
|
+
const directory = path.join(root, 'docs', folder)
|
|
14
|
+
if (await fs.realpath(directory).catch(() => '') !== directory) continue
|
|
15
|
+
const entries = await fs.readdir(directory, { withFileTypes: true, recursive: true })
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
if (!entry.isFile() || !/\.(md|markdown)$/i.test(entry.name)) continue
|
|
18
|
+
const file = path.relative(root, path.join(entry.parentPath, entry.name)).split(path.sep).join('/')
|
|
19
|
+
documents.push({ group, title: path.parse(entry.name).name, file })
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return documents.sort((a, b) => a.group === b.group ? a.file.localeCompare(b.file, 'zh') : 0)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function archiveScript(file, original) {
|
|
26
|
+
const directory = path.join(path.dirname(file), 'archive')
|
|
27
|
+
mkdirSync(directory, { recursive: true })
|
|
28
|
+
if (realpathSync(directory) !== directory) throw new Error('Invalid script archive')
|
|
29
|
+
const versions = readdirSync(directory).map(name => /^v(\d+)\.md$/.exec(name))
|
|
30
|
+
.filter(Boolean).map(match => Number(match[1]))
|
|
31
|
+
const version = String(Math.max(0, ...versions) + 1).padStart(3, '0')
|
|
32
|
+
const archived = path.join(directory, 'v' + version + '.md')
|
|
33
|
+
writeFileSync(archived, original, { flag: 'wx' })
|
|
34
|
+
return archived
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function archiveStoryboard(file) {
|
|
38
|
+
const group = path.dirname(file)
|
|
39
|
+
const archive = path.join(group, 'archive')
|
|
40
|
+
mkdirSync(archive, { recursive: true })
|
|
41
|
+
if (realpathSync(archive) !== archive) throw new Error('Invalid storyboard archive')
|
|
42
|
+
const numbers = readdirSync(archive).map(name => Number(/^v(\d+)$/.exec(name)?.[1]) || 0)
|
|
43
|
+
const version = path.join(archive, 'v' + String(Math.max(0, ...numbers) + 1).padStart(3, '0'))
|
|
44
|
+
mkdirSync(version)
|
|
45
|
+
try {
|
|
46
|
+
for (const entry of readdirSync(group, { withFileTypes: true })) {
|
|
47
|
+
if (entry.isFile() && /\.(md|markdown|png|jpe?g|webp|avif)$/i.test(entry.name)) {
|
|
48
|
+
copyFileSync(path.join(group, entry.name), path.join(version, entry.name), constants.COPYFILE_FICLONE)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return version
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
rmSync(version, { recursive: true, force: true })
|
|
54
|
+
throw cause
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const types = { '.markdown': 'text/plain; charset=utf-8', '.md': 'text/plain; charset=utf-8', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp', '.avif': 'image/avif', '.gif': 'image/gif' }
|
|
16
59
|
|
|
17
60
|
export function projectSettings() {
|
|
18
61
|
return {
|
|
@@ -21,13 +64,13 @@ export function projectSettings() {
|
|
|
21
64
|
server.middlewares.use(async (req, res, next) => {
|
|
22
65
|
const url = new URL(req.url, 'http://localhost')
|
|
23
66
|
if (url.pathname !== '/api/settings') return next()
|
|
24
|
-
if (req.method !== 'GET') {
|
|
67
|
+
if (req.method !== 'GET' && !(req.method === 'PUT' && url.searchParams.has('file'))) {
|
|
25
68
|
res.statusCode = 405
|
|
26
69
|
return res.end()
|
|
27
70
|
}
|
|
28
71
|
if (!url.searchParams.has('file')) {
|
|
29
72
|
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
30
|
-
return res.end(JSON.stringify(
|
|
73
|
+
return res.end(JSON.stringify(await listDocuments()))
|
|
31
74
|
}
|
|
32
75
|
const requested = url.searchParams.get('file')
|
|
33
76
|
const allowedRoot = requested.split('/')[0]
|
|
@@ -40,6 +83,52 @@ export function projectSettings() {
|
|
|
40
83
|
return res.end('找不到项目文档或参考图')
|
|
41
84
|
}
|
|
42
85
|
try {
|
|
86
|
+
if (req.method === 'PUT') {
|
|
87
|
+
const isStoryboard = allowedRoot === 'storyboard'
|
|
88
|
+
const isScript = allowedRoot === 'scripts'
|
|
89
|
+
const [, folder, filename] = requested.split('/')
|
|
90
|
+
const editable = isScript
|
|
91
|
+
? requested === ['scripts', folder, filename].join('/') &&
|
|
92
|
+
(await listScripts()).some(script => script.name === folder && script.documents.includes(filename))
|
|
93
|
+
: isStoryboard
|
|
94
|
+
? (await listStoryboard()).some(episode => episode.scenes.some(scene =>
|
|
95
|
+
scene.groups.some(group => group.documents.some(doc => doc.file === requested))))
|
|
96
|
+
: (await listDocuments()).some(document => document.file === requested)
|
|
97
|
+
if (!editable) {
|
|
98
|
+
res.statusCode = 404
|
|
99
|
+
return res.end(isScript ? '找不到可编辑的剧本文档' : '找不到设定文档')
|
|
100
|
+
}
|
|
101
|
+
const chunks = []
|
|
102
|
+
for await (const chunk of req) chunks.push(chunk)
|
|
103
|
+
const patch = JSON.parse(Buffer.concat(chunks).toString('utf8'))
|
|
104
|
+
if (typeof patch?.markdown !== 'string' || typeof patch.original !== 'string') {
|
|
105
|
+
res.statusCode = 400
|
|
106
|
+
return res.end('保存内容无效')
|
|
107
|
+
}
|
|
108
|
+
if (readFileSync(file, 'utf8') !== patch.original) {
|
|
109
|
+
res.statusCode = 409
|
|
110
|
+
return res.end('文档已在其他位置修改,请保留草稿并重新载入。')
|
|
111
|
+
}
|
|
112
|
+
if (patch.original === patch.markdown) {
|
|
113
|
+
res.statusCode = 204
|
|
114
|
+
return res.end()
|
|
115
|
+
}
|
|
116
|
+
let archived
|
|
117
|
+
const temporary = file + '.' + randomUUID() + '.tmp'
|
|
118
|
+
try {
|
|
119
|
+
writeFileSync(temporary, patch.markdown, { flag: 'wx' })
|
|
120
|
+
if (isScript && filename === 'index.md') archived = archiveScript(file, patch.original)
|
|
121
|
+
if (isStoryboard) archived = archiveStoryboard(file)
|
|
122
|
+
renameSync(temporary, file)
|
|
123
|
+
} catch (cause) {
|
|
124
|
+
if (archived) rmSync(archived, { recursive: isStoryboard, force: true })
|
|
125
|
+
throw cause
|
|
126
|
+
} finally {
|
|
127
|
+
rmSync(temporary, { force: true })
|
|
128
|
+
}
|
|
129
|
+
res.statusCode = 204
|
|
130
|
+
return res.end()
|
|
131
|
+
}
|
|
43
132
|
const data = await fs.readFile(file)
|
|
44
133
|
res.setHeader('Content-Type', type)
|
|
45
134
|
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { projectRoot } from './project-paths.js'
|
|
4
|
+
import { streamMedia } from './image-assets.js'
|
|
5
|
+
|
|
6
|
+
const root = path.join(projectRoot, 'storyboard')
|
|
7
|
+
const videoRoot = path.join(projectRoot, 'dist', 'storyboard')
|
|
8
|
+
const numbered = /^\d{3}-.+/
|
|
9
|
+
const special = name => ['opening', 'ending'].includes(name)
|
|
10
|
+
const types = { __proto__: null, png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', avif: 'image/avif', mp4: 'video/mp4', mov: 'video/quicktime', webm: 'video/webm', mkv: 'video/x-matroska', m4v: 'video/mp4' }
|
|
11
|
+
const mediaType = name => types[path.extname(name).slice(1).toLowerCase()]
|
|
12
|
+
const isDefault = name => /^index\./i.test(name)
|
|
13
|
+
|
|
14
|
+
async function entries(parts, base = root) {
|
|
15
|
+
const dir = path.join(base, ...parts)
|
|
16
|
+
if (await fs.realpath(dir).catch(() => '') !== dir) return []
|
|
17
|
+
return (await fs.readdir(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name, 'zh', { numeric: true }))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function group(parts) {
|
|
21
|
+
const media = []
|
|
22
|
+
const local = await entries(parts)
|
|
23
|
+
const outputs = (await entries(parts, videoRoot)).filter(entry => entry.isFile() && mediaType(entry.name)?.startsWith('video/'))
|
|
24
|
+
const files = new Map([...local, ...outputs].map(entry => [entry.name, entry]))
|
|
25
|
+
for (const entry of files.values()) {
|
|
26
|
+
const type = mediaType(entry.name)
|
|
27
|
+
if (!entry.isFile() || !type) continue
|
|
28
|
+
const video = type.startsWith('video/')
|
|
29
|
+
if (!video && !/^\d+-/.test(entry.name)) continue
|
|
30
|
+
const base = outputs.includes(entry) ? videoRoot : root
|
|
31
|
+
const stat = await fs.stat(path.join(base, ...parts, entry.name)).catch(() => null)
|
|
32
|
+
if (!stat) continue
|
|
33
|
+
media.push({ name: entry.name, video, primary: video && isDefault(entry.name),
|
|
34
|
+
url: '/api/storyboard?file=' + encodeURIComponent([...parts, entry.name].join('/')) + '&modified=' + stat.mtimeMs })
|
|
35
|
+
}
|
|
36
|
+
media.sort((a, b) => Number(a.video) - Number(b.video) || Number(b.primary) - Number(a.primary))
|
|
37
|
+
const documents = ['分镜.md', '生图.md', '即梦.md']
|
|
38
|
+
.filter(name => local.some(entry => entry.isFile() && entry.name === name))
|
|
39
|
+
.map(name => ({ name, file: ['storyboard', ...parts, name].join('/') }))
|
|
40
|
+
return { name: parts.at(-1), media, documents }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function listStoryboard() {
|
|
44
|
+
const episodes = []
|
|
45
|
+
for (const episode of await entries([])) {
|
|
46
|
+
if (!episode.isDirectory() || !(numbered.test(episode.name) || special(episode.name))) continue
|
|
47
|
+
const scenes = []
|
|
48
|
+
for (const scene of await entries([episode.name])) {
|
|
49
|
+
if (!scene.isDirectory() || !(numbered.test(scene.name) || special(episode.name) && scene.name === '关键帧')) continue
|
|
50
|
+
const parts = [episode.name, scene.name]
|
|
51
|
+
const segments = (await entries(parts)).filter(e => e.isDirectory() && numbered.test(e.name))
|
|
52
|
+
scenes.push({ name: scene.name, groups: segments.length ? await Promise.all(segments.map(e => group([...parts, e.name]))) : [await group(parts)] })
|
|
53
|
+
}
|
|
54
|
+
episodes.push({ name: episode.name, scenes })
|
|
55
|
+
}
|
|
56
|
+
return episodes.sort((a, b) => (a.name === 'opening' ? -1 : Number(a.name === 'ending')) - (b.name === 'opening' ? -1 : Number(b.name === 'ending')))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function projectStoryboard() {
|
|
60
|
+
return { name: 'workbench-storyboard', configureServer(server) {
|
|
61
|
+
server.middlewares.use('/api/storyboard', async (req, res) => {
|
|
62
|
+
try {
|
|
63
|
+
if (req.method !== 'GET') { res.statusCode = 405; return res.end() }
|
|
64
|
+
const file = new URL(req.url, 'http://localhost').searchParams.get('file')
|
|
65
|
+
if (file === null) {
|
|
66
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
67
|
+
return res.end(JSON.stringify(await listStoryboard()))
|
|
68
|
+
}
|
|
69
|
+
const parts = file.split('/')
|
|
70
|
+
const [episode, scene] = parts
|
|
71
|
+
const type = mediaType(parts.at(-1))
|
|
72
|
+
if (![3, 4].includes(parts.length) || !(special(episode) || numbered.test(episode)) ||
|
|
73
|
+
!(numbered.test(scene) || special(episode) && scene === '关键帧') ||
|
|
74
|
+
(parts.length === 4 && !numbered.test(parts[2])) || !type) {
|
|
75
|
+
res.statusCode = 404
|
|
76
|
+
return res.end()
|
|
77
|
+
}
|
|
78
|
+
for (const base of type.startsWith('video/') ? [videoRoot, root] : [root]) {
|
|
79
|
+
const target = path.join(base, ...parts)
|
|
80
|
+
if (await fs.realpath(target).catch(() => '') !== target || !(await fs.stat(target)).isFile()) continue
|
|
81
|
+
res.setHeader('Content-Type', type)
|
|
82
|
+
return await streamMedia(target, req, res)
|
|
83
|
+
}
|
|
84
|
+
res.statusCode = 404
|
|
85
|
+
return res.end()
|
|
86
|
+
} catch { res.statusCode = 500; res.end() }
|
|
87
|
+
})
|
|
88
|
+
} }
|
|
89
|
+
}
|
|
@@ -30,7 +30,7 @@ a:focus-visible { text-decoration: underline; text-decoration-thickness: 2px; }
|
|
|
30
30
|
@media (forced-colors: active) { :focus-visible { outline: 1px solid Highlight; outline-offset: -1px; } }
|
|
31
31
|
.shell { display: grid; min-height: 100vh; grid-template-columns: 208px minmax(0, 1fr); }
|
|
32
32
|
.sidebar { position: sticky; top: 0; height: 100vh; background: #fff; border-right: 1px solid var(--line); padding: 24px 14px; }
|
|
33
|
-
.brand { display: flex; align-items: center; gap: 11px; margin: 0 8px 40px; }
|
|
33
|
+
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 11px; margin: 0 8px 40px; }
|
|
34
34
|
.brand-icon { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--accent); color: #fff; }
|
|
35
35
|
.brand-icon:has(img) { background: transparent; }
|
|
36
36
|
.brand-icon img { display: block; width: 100%; height: 100%; object-fit: contain; }
|
|
@@ -41,6 +41,7 @@ a:focus-visible { text-decoration: underline; text-decoration-thickness: 2px; }
|
|
|
41
41
|
.sidebar .nav-link { text-decoration: none; display: flex; align-items: center; gap: 9px; width: 100%; border: 0; border-radius: 8px; padding: 10px 11px; margin-bottom: 4px; background: transparent; color: #4b5367; text-align: left; font-size: 14px; }
|
|
42
42
|
.sidebar .nav-link:hover { background: #f4f4f9; }
|
|
43
43
|
.sidebar .nav-link.selected { color: var(--accent); background: var(--accent-bg); font-weight: 650; }
|
|
44
|
+
.sidebar .nav-link + .nav-title { margin-top: 16px; }
|
|
44
45
|
.nav-arrow { margin-left: auto; }
|
|
45
46
|
.topbar { display: flex; align-items: center; gap: 9px; height: 65px; padding: 0 34px; background: #fff; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
|
|
46
47
|
.topbar strong { color: #33384a; }
|
|
@@ -57,6 +58,7 @@ a:focus-visible { text-decoration: underline; text-decoration-thickness: 2px; }
|
|
|
57
58
|
background: transparent;
|
|
58
59
|
color: var(--accent);
|
|
59
60
|
}
|
|
61
|
+
.topbar-icon-button.language-trigger { display: inline-flex; align-items: center; gap: 4px; width: auto; padding-inline: 8px; }
|
|
60
62
|
.topbar-icon-button:hover, .oss-sync-trigger.is-running { background: var(--accent-bg); }
|
|
61
63
|
.oss-sync-trigger.has-count {
|
|
62
64
|
display: inline-flex;
|
|
@@ -167,18 +169,6 @@ a:focus-visible { text-decoration: underline; text-decoration-thickness: 2px; }
|
|
|
167
169
|
.project-logo-field .brand-icon { width: 64px; height: 64px; border: 1px solid var(--line); }
|
|
168
170
|
.project-logo-field img { object-fit: contain; padding: 4px; }
|
|
169
171
|
.project-logo-field .upload:focus-within { box-shadow: inset 0 0 0 1px var(--focus-border); }
|
|
170
|
-
.storage-lfs-target {
|
|
171
|
-
display: grid;
|
|
172
|
-
gap: 4px;
|
|
173
|
-
padding: 12px 14px;
|
|
174
|
-
border-radius: 8px;
|
|
175
|
-
background: var(--accent-bg);
|
|
176
|
-
color: #33384a;
|
|
177
|
-
font-size: 13px;
|
|
178
|
-
}
|
|
179
|
-
.storage-lfs-target strong { color: var(--accent); }
|
|
180
|
-
.storage-lfs-target p { margin: 0; }
|
|
181
|
-
.storage-lfs-target code { overflow-wrap: anywhere; }
|
|
182
172
|
.storage-test-button { margin-inline-end: auto; }
|
|
183
173
|
.storage-test-result {
|
|
184
174
|
display: grid;
|
|
@@ -462,7 +452,6 @@ audio { max-width: 100%; }
|
|
|
462
452
|
@media (max-width: 720px) {
|
|
463
453
|
.sidebar { flex-wrap: wrap; }
|
|
464
454
|
}
|
|
465
|
-
.sidebar .settings-nav { margin-bottom: 20px; }
|
|
466
455
|
.settings-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); align-items: start; gap: 20px; margin-top: 19px; }
|
|
467
456
|
.settings-index, .settings-reader { min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
|
|
468
457
|
.settings-index { padding: 11px; }
|
|
@@ -471,9 +460,19 @@ audio { max-width: 100%; }
|
|
|
471
460
|
.settings-index button { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 8px; text-align: left; border: 0; border-radius: 6px; background: #fff; color: var(--ink, #21263b); font-size: 13px; }
|
|
472
461
|
.settings-index button.current, .settings-index button:hover { color: var(--accent); background: var(--accent-bg); }
|
|
473
462
|
.settings-reader { padding: clamp(14px, 3vw, 32px); }
|
|
463
|
+
.settings-reader .asset-story-actions { position: sticky; top: 0; z-index: 1; background: white; padding-block: 6px; }
|
|
464
|
+
.settings-reader .asset-story-panel { height: auto; overflow: visible; }
|
|
465
|
+
.settings-reader textarea { min-height: 58dvh; }
|
|
474
466
|
.settings-source { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
|
|
475
467
|
.settings-reader .markdown { line-height: 1.8; }
|
|
476
468
|
@media (max-width: 720px) {
|
|
477
|
-
.sidebar .settings-nav { margin-bottom: 0; }
|
|
478
469
|
.settings-layout { grid-template-columns: minmax(0, 1fr); }
|
|
479
470
|
}
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 16px; margin-top: 20px; }
|
|
474
|
+
.overview-card { position: relative; display: grid; gap: 18px; padding: 20px; color: inherit; text-decoration: none; border: 1px solid var(--line); border-radius: 12px; background: white; }
|
|
475
|
+
.overview-card:hover, .overview-card:focus-visible { border-color: var(--accent); }
|
|
476
|
+
.overview-label { display: flex; gap: 8px; align-items: center; color: var(--muted); }
|
|
477
|
+
.overview-card strong { font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
|
|
478
|
+
.overview-arrow { position: absolute; right: 16px; bottom: 20px; color: var(--muted); }
|
|
@@ -6,6 +6,8 @@ export default {
|
|
|
6
6
|
props: {
|
|
7
7
|
draft: { type: String, default: null },
|
|
8
8
|
busy: Boolean,
|
|
9
|
+
readOnly: Boolean,
|
|
10
|
+
label: { type: String, default: 'README.md' },
|
|
9
11
|
},
|
|
10
12
|
emits: ['edit', 'cancel', 'save', 'update:draft'],
|
|
11
13
|
}
|
|
@@ -13,18 +15,22 @@ export default {
|
|
|
13
15
|
|
|
14
16
|
<template>
|
|
15
17
|
<form @submit.prevent="$emit('save')">
|
|
16
|
-
<div class="asset-story-actions">
|
|
17
|
-
<span>
|
|
18
|
-
<div
|
|
19
|
-
<
|
|
20
|
-
<
|
|
18
|
+
<div v-if="label" class="asset-story-actions">
|
|
19
|
+
<span>{{ label }}</span>
|
|
20
|
+
<div class="dialog-actions">
|
|
21
|
+
<slot name="actions" />
|
|
22
|
+
<div v-if="draft !== null" class="dialog-actions">
|
|
23
|
+
<button type="button" class="secondary" :disabled="busy" @click="$emit('cancel')">{{ $t('取消') }}</button>
|
|
24
|
+
<button class="primary" :disabled="busy">{{ $t('保存') }}</button>
|
|
25
|
+
</div>
|
|
26
|
+
<button v-else-if="!readOnly" type="button" class="secondary" :disabled="busy" @click="$emit('edit')">
|
|
27
|
+
<Pencil :size="15" aria-hidden="true" />{{ $t('编辑') }}
|
|
28
|
+
</button>
|
|
21
29
|
</div>
|
|
22
|
-
<button v-else type="button" class="secondary" :disabled="busy" @click="$emit('edit')">
|
|
23
|
-
<Pencil :size="15" aria-hidden="true" />{{ $t('编辑') }}
|
|
24
|
-
</button>
|
|
25
30
|
</div>
|
|
31
|
+
<slot name="header" />
|
|
26
32
|
<div class="asset-story-panel">
|
|
27
|
-
<textarea v-if="draft !== null" :value="draft" aria-label="
|
|
33
|
+
<textarea v-if="draft !== null" :value="draft" :aria-label="label" :disabled="busy"
|
|
28
34
|
@input="$emit('update:draft', $event.target.value)"></textarea>
|
|
29
35
|
<slot v-else />
|
|
30
36
|
</div>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { marked } from 'marked'
|
|
3
|
+
import { Copy } from 'lucide-vue-next'
|
|
4
|
+
import ProjectMarkdown from './ProjectMarkdown.vue'
|
|
5
|
+
|
|
6
|
+
function promptSections(markdown) {
|
|
7
|
+
const sections = []
|
|
8
|
+
let section = { source: '', prompt: '' }
|
|
9
|
+
let prose = false
|
|
10
|
+
function finish() {
|
|
11
|
+
if (section.source.trim()) sections.push(section)
|
|
12
|
+
section = { source: '', prompt: '' }
|
|
13
|
+
prose = false
|
|
14
|
+
}
|
|
15
|
+
for (const token of marked.lexer(markdown)) {
|
|
16
|
+
if (token.type === 'code' || token.type === 'blockquote') {
|
|
17
|
+
finish()
|
|
18
|
+
sections.push({ source: token.raw, prompt: token.text })
|
|
19
|
+
continue
|
|
20
|
+
}
|
|
21
|
+
if (token.type === 'heading') finish()
|
|
22
|
+
if (token.type === 'paragraph' && /^可复制提示词[::]\s*$/.test(token.text)) {
|
|
23
|
+
finish()
|
|
24
|
+
section.source = token.raw
|
|
25
|
+
finish()
|
|
26
|
+
prose = true
|
|
27
|
+
continue
|
|
28
|
+
}
|
|
29
|
+
if (!prose && token.type === 'paragraph' && /^生成/.test(token.text)) {
|
|
30
|
+
finish()
|
|
31
|
+
prose = true
|
|
32
|
+
}
|
|
33
|
+
section.source += token.raw
|
|
34
|
+
if (prose) section.prompt += token.raw
|
|
35
|
+
}
|
|
36
|
+
finish()
|
|
37
|
+
return sections
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
components: { Copy, ProjectMarkdown },
|
|
42
|
+
props: { source: String, file: String },
|
|
43
|
+
data() { return { feedback: null } },
|
|
44
|
+
computed: { sections() { return promptSections(this.source) } },
|
|
45
|
+
methods: {
|
|
46
|
+
async copy(section, index) {
|
|
47
|
+
try {
|
|
48
|
+
await navigator.clipboard.writeText(section.prompt.trim())
|
|
49
|
+
this.feedback = { index, label: '已复制' }
|
|
50
|
+
} catch {
|
|
51
|
+
this.feedback = { index, label: '复制失败' }
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
</script>
|
|
57
|
+
<template>
|
|
58
|
+
<section v-for="(section, i) in sections" :key="i">
|
|
59
|
+
<div v-if="section.prompt.trim()" class="prompt-actions">
|
|
60
|
+
<button type="button" class="secondary" @click="copy(section, i)">
|
|
61
|
+
<Copy :size="14" /><span aria-live="polite">{{ $t(feedback?.index === i ? feedback.label : '复制提示词') }}</span>
|
|
62
|
+
</button>
|
|
63
|
+
</div>
|
|
64
|
+
<ProjectMarkdown :source="section.source" :file="file" show-images />
|
|
65
|
+
</section>
|
|
66
|
+
</template>
|
|
67
|
+
<style scoped>
|
|
68
|
+
.prompt-actions { display:flex; justify-content:flex-end; margin:8px 0 4px }
|
|
69
|
+
</style>
|