diff --git a/database.sqlite3 b/database.sqlite3 index e2cbf91..23c1a34 100644 Binary files a/database.sqlite3 and b/database.sqlite3 differ diff --git a/index.js b/index.js index 066f03b..77f1cda 100644 --- a/index.js +++ b/index.js @@ -172,24 +172,31 @@ app.post("/api/upload_video", authorized(), fileUpload({ limits: { fileSize: 2 * const id = randomString(4); const tempPath = req.files.video.tempFilePath; const newPath = path.join(dirname(), "videos", `${id}.mp4`); + const thumbnailPath = path.join(dirname(), "videos", `${id}.png`); console.log(newPath); - const exitCode = await new Promise((resolve, _reject) => { + let exitCode = await new Promise(resolve => { const process = childProcess.spawn("ffmpeg", ["-i", tempPath, "-b:v", "1M", "-b:a", "192k", newPath]); - process.stderr.on("data", (data) => { - console.error(data.toString()); - }); - process.on("close", (code) => { - resolve(code); - }) + process.stderr.on("data", (data) => console.error(data.toString())); + process.on("close", resolve); }); if (exitCode !== 0) { throw new Error("ffmpeg failed"); } - await dbRun("INSERT INTO videos (id, user_id, title, path) VALUES (?, ?, ?, ?)", id, userId, title, newPath); + exitCode = await new Promise(resolve => { + const process = childProcess.spawn("ffmpeg", ["-i", tempPath, "-ss", "00:00:01.000", "-vframes", "1", thumbnailPath]); + process.stderr.on("data", (data) => console.error(data.toString())); + process.on("close", resolve); + }); + + if (exitCode !== 0) { + throw new Error("thumbnail generation failed"); + } + + await dbRun("INSERT INTO videos (id, user_id, title) VALUES (?, ?, ?)", id, userId, title); return res.status(200).json({ ok: true }); }) diff --git a/migration.sql b/migration.sql index 569f0d9..dcff1ff 100644 --- a/migration.sql +++ b/migration.sql @@ -8,7 +8,6 @@ CREATE TABLE videos ( id TEXT PRIMARY KEY NOT NULL, user_id INTEGER, title TEXT NOT NULL, - path TEXT NOT NULL, FOREIGN KEY(user_id) REFERENCES users(id) ); diff --git a/public/search/script.js b/public/search/script.js index d11fb3f..4a3c1b4 100644 --- a/public/search/script.js +++ b/public/search/script.js @@ -24,9 +24,20 @@ function displayResponse(response) { + videos .map(v => { console.log(v); - return `
${v.title} - ${v.author}
+
+
+ ${v.title}
+
+ by ${v.author}
+
+