From 6369fcf58d61c8cb3b32914cf18e683631558c31 Mon Sep 17 00:00:00 2001 From: synt-xerror <169557594+synt-xerror@users.noreply.github.com> Date: Tue, 21 Apr 2026 10:27:00 -0300 Subject: [PATCH] video uploads to the server and returns a link to the user. and a fix on manager script, that now it update the registry with the content of manyplug, instead of just the version --- manager.js | 8 ++++---- registry.json | 25 ++++++++++++++++++++----- video/index.js | 40 +++++++++++++++++++++++++++++++--------- video/manyplug.json | 15 ++++++++++++--- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/manager.js b/manager.js index 5188c40..3c275b6 100644 --- a/manager.js +++ b/manager.js @@ -50,14 +50,14 @@ for (const entry of entries) { version: manifest.version }); registry.plugins[pluginName] = manifest; - } else if (existing.version !== manifest.version) { + } else if (JSON.stringify(existing, Object.keys(existing).sort()) !== JSON.stringify(manifest, Object.keys(manifest).sort())) { const oldVersion = existing.version; - existing.version = manifest.version; - + registry.plugins[pluginName] = manifest; + update.push({ name: pluginName, oldVersion: oldVersion, - newVersion: existing.version + newVersion: manifest.version }); } } catch (err) { diff --git a/registry.json b/registry.json index f9d7e33..e857010 100644 --- a/registry.json +++ b/registry.json @@ -1,16 +1,17 @@ { - "lastUpdated": "2026-04-21T05:56:16.900Z", + "lastUpdated": "2026-04-21T13:23:13.743Z", "plugins": { "a": { "name": "a", - "author": "freakk.dev", + "author": "SyntaxError (https://git.maneos.net)", "version": "1.0.0", - "category": "humor", + "category": "fun", "service": false, "dependencies": {} }, "adivinhacao": { "name": "adivinhacao", + "author": "SyntaxError (https://git.maneos.net)", "version": "1.0.0", "category": "games", "service": false, @@ -18,6 +19,7 @@ }, "audio": { "name": "audio", + "author": "SyntaxError (https://git.maneos.net)", "version": "1.0.0", "category": "media", "service": false, @@ -25,6 +27,7 @@ }, "figurinha": { "name": "figurinha", + "author": "SyntaxError (https://git.maneos.net)", "version": "1.0.0", "category": "media", "service": false, @@ -34,6 +37,7 @@ }, "forca": { "name": "forca", + "author": "SyntaxError (https://git.maneos.net)", "version": "1.0.0", "category": "games", "service": false, @@ -41,6 +45,7 @@ }, "many": { "name": "many", + "author": "SyntaxError (https://git.maneos.net)", "version": "1.0.0", "category": "utility", "service": false, @@ -48,10 +53,20 @@ }, "video": { "name": "video", - "version": "1.0.0", + "author": "SyntaxError (https://git.maneos.net)", + "version": "2.0.0", "category": "media", "service": false, - "dependencies": {} + "externalDependencies": { + "yt-dlp": { + "command": "yt-dlp", + "optional": false + }, + "ffmpeg": { + "command": "ffmpeg", + "optional": false + } + } }, "obrigado": { "name": "obrigado", diff --git a/video/index.js b/video/index.js index b06777b..c3571ed 100644 --- a/video/index.js +++ b/video/index.js @@ -1,14 +1,13 @@ /** * plugins/video/index.js * - * Downloads video via yt-dlp and sends to chat. - * All processing (download + send + cleanup) is here. + * Downloads video via yt-dlp and uploads to server. + * All processing (download + upload + cleanup) is here. */ import { spawn } from "child_process"; import fs from "fs"; import path from "path"; -import os from "os"; import { enqueue } from "../../download/queue.js"; import { CMD_PREFIX } from "../../config.js"; import { createPluginI18n } from "../../utils/pluginI18n.js"; @@ -20,7 +19,8 @@ const logStream = fs.createWriteStream("logs/video-error.log", { flags: "a" }); logStream.on("error", err => console.error("[logStream]", err)); const DOWNLOADS_DIR = path.resolve("downloads"); -const YT_DLP = os.platform() === "win32" ? ".\\bin\\yt-dlp.exe" : "./bin/yt-dlp"; +const YT_DLP = "yt-dlp"; +const UPLOAD_URL = "http://maneos.net/upload"; const ARGS_BASE = [ "--extractor-args", "youtube:player_client=android", @@ -39,7 +39,6 @@ const ARGS_BASE = [ function downloadVideo(url, id) { return new Promise((resolve, reject) => { - // Isolated folder just for this download const tmpDir = path.join(DOWNLOADS_DIR, id); fs.mkdirSync(tmpDir, { recursive: true }); @@ -62,10 +61,8 @@ function downloadVideo(url, id) { return reject(new Error(t("error.downloadFailed"))); } - // Try stdout path first let filePath = stdout.trim().split("\n").filter(Boolean).at(-1); - // Fallback: get the single file inside the isolated folder if (!filePath || !fs.existsSync(filePath)) { const files = fs.readdirSync(tmpDir).filter(f => !f.endsWith(".part")); filePath = files.length === 1 ? path.join(tmpDir, files[0]) : null; @@ -81,6 +78,30 @@ function downloadVideo(url, id) { }); } +async function uploadToServer(filePath) { + const fileBuffer = fs.readFileSync(filePath); + const fileName = path.basename(filePath); + + const formData = new FormData(); + formData.append("file", new Blob([fileBuffer]), fileName); + + const response = await fetch(UPLOAD_URL, { + method: "POST", + body: formData, + }); + + if (!response.ok) { + throw new Error(`Upload failed: ${response.status} ${response.statusText}`); + } + + const result = await response.json(); + if (!result.url) { + throw new Error("Server response missing url"); + } + + return result.url.startsWith("http") ? result.url : `http://maneos.net${result.url}`; +} + export default async function ({ msg, api }) { if (!msg.is(CMD_PREFIX + "video")) return; @@ -98,7 +119,8 @@ export default async function ({ msg, api }) { enqueue( async () => { const { filePath, tmpDir } = await downloadVideo(url, id); - await api.sendVideo(filePath); + const downloadUrl = await uploadToServer(filePath); + await msg.reply(downloadUrl); fs.rmSync(tmpDir, { recursive: true, force: true }); api.log.info(`${CMD_PREFIX}video completed → ${url}`); }, @@ -106,4 +128,4 @@ export default async function ({ msg, api }) { await msg.reply(t("error.generic")); } ); -} \ No newline at end of file +} diff --git a/video/manyplug.json b/video/manyplug.json index 11d6b6a..1dd2c9e 100644 --- a/video/manyplug.json +++ b/video/manyplug.json @@ -1,8 +1,17 @@ { "name": "video", "author": "SyntaxError (https://git.maneos.net)", - "version": "1.0.0", + "version": "2.0.0", "category": "media", "service": false, - "dependencies": {} -} \ No newline at end of file + "externalDependencies": { + "yt-dlp": { + "command": "yt-dlp", + "optional": false + }, + "ffmpeg": { + "command": "ffmpeg", + "optional": false + } + } +}