marriedtermiteblyi commited on
Commit
7869802
·
verified ·
1 Parent(s): 7411ef2

put notes/7ad7f059-f4f1-4b57-95fa-ef921a5d7e75.json

Browse files
notes/7ad7f059-f4f1-4b57-95fa-ef921a5d7e75.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "id": "7ad7f059-f4f1-4b57-95fa-ef921a5d7e75",
3
+ "title": "note.js",
4
+ "content": "\nconst axios = require('axios');\nconst fs = require('fs');\nconst pathLib = require('path');\n\nconst BASE_URL = 'https://twannote.vercel.app';\n\nfunction detectLanguageByExt(filePath) {\n const ext = pathLib.extname(filePath).slice(1).toLowerCase();\n const map = {\n js: 'javascript',\n mjs: 'javascript',\n cjs: 'javascript',\n ts: 'typescript',\n py: 'python',\n json: 'json',\n html: 'html',\n htm: 'html',\n css: 'css',\n md: 'markdown',\n sh: 'bash',\n bash: 'bash',\n txt: 'text'\n };\n return map[ext] || 'text';\n}\n\nasync function createNoteOnAPI(filePath) {\n const content = fs.readFileSync(filePath, 'utf8');\n const title = pathLib.basename(filePath);\n const language = detectLanguageByExt(filePath);\n\n const res = await axios.post(`${BASE_URL}/api/code`, {\n title,\n content,\n language\n }, { timeout: 20000 });\n\n const id = res.data?.id;\n if (!id) throw new Error('API trả về không có id');\n\n const rawUrl = `${BASE_URL}/code/${id}/raw`;\n const viewUrl = `${BASE_URL}/api/code/${id}`; // JSON view\n const pageUrl = `${BASE_URL}/code/${id}`; // nếu có trang UI /code/:id\n\n return { id, rawUrl, viewUrl, pageUrl };\n}\n\nthis.config = {\n name: \"note\",\n version: \"2.0.0\",\n hasPermssion: 0,\n credits: \"twan\",\n description: \"note\",\n commandCategory: \"Tiện ích\",\n usages: \"..\",\n cooldowns: 5,\n};\n\n\nthis.run = async function (o) {\n const name = this.config.name;\n const maybeUrl = o.event?.messageReply?.args?.[0] || o.args[1];\n let targetPath = `${__dirname}/${o.args[0]}`;\n const send = msg => new Promise(r => o.api.sendMessage(msg, o.event.threadID, (err, res) => r(res), o.event.messageID));\n\n try {\n if (/^https?:\\/\\//i.test(maybeUrl)) {\n return send(`🔗 URL: ${maybeUrl}\\n📄 File đích: ${targetPath}\\n\\nThả cảm xúc để **xác nhận** thay thế nội dung file từ URL này.`).then(res => {\n res = {\n ...res,\n name,\n path: targetPath,\n o,\n url: maybeUrl,\n action: 'confirm_replace_content_from_url',\n };\n global.client.handleReaction.push(res);\n });\n }\n\n if (!fs.existsSync(targetPath)) {\n return send(`❎ Đường dẫn file không tồn tại để upload: ${targetPath}`);\n }\n\n const { id, rawUrl, viewUrl, pageUrl } = await createNoteOnAPI(targetPath);\n\n return send(\n `📝 Đã tạo note trên API\\n` +\n `• ID: ${id}\\n` +\n `• Raw: ${rawUrl}\\n` +\n `• JSON: ${viewUrl}\\n` +\n `• Page: ${pageUrl}\\n` +\n `────────────────\\n` +\n `📄 File nguồn: ${targetPath}\\n\\n` +\n `📌 Thả cảm xúc để **tải nội dung từ Raw về và ghi đè** file nguồn.`\n ).then(res => {\n res = {\n ...res,\n name,\n path: targetPath,\n o,\n url: rawUrl,\n action: 'confirm_replace_content_from_url',\n };\n global.client.handleReaction.push(res);\n });\n\n } catch (e) {\n console.error(e);\n send(e.toString());\n }\n};\n\nthis.handleReaction = async function (o) {\n const _ = o.handleReaction;\n const send = msg => new Promise(r => o.api.sendMessage(msg, o.event.threadID, (err, res) => r(res), o.event.messageID));\n\n try {\n if (o.event.userID != _.o.event.senderID) return;\n\n switch (_.action) {\n case 'confirm_replace_content_from_url': {\n const content = (await axios.get(_.url, { responseType: 'text', timeout: 20000 })).data;\n fs.writeFileSync(_.path, content);\n send(`✅ Đã ghi đè nội dung file\\n\\n🔗 File: ${_.path}`);\n } break;\n\n default:\n break;\n }\n } catch (e) {\n console.error(e);\n send(e.toString());\n }\n};",
5
+ "language": "javascript",
6
+ "createdAt": 1755533276228,
7
+ "updatedAt": 1755533276228
8
+ }