cross/flow.json
2024-03-11 21:10:49 -04:00

831 lines
33 KiB
JSON

[
{
"id": "503ae6a51f28e7b1",
"type": "tab",
"label": "Crossposter",
"disabled": false,
"info": "",
"env": [
{
"name": "IG_USERNAME",
"value": "sciencegirl100",
"type": "str"
},
{
"name": "IG_PASSWORD",
"value": "REDACTED",
"type": "str"
}
]
},
{
"id": "dbbaebd1d08b6537",
"type": "junction",
"z": "503ae6a51f28e7b1",
"x": 560,
"y": 540,
"wires": [
[
"1a034ddb27d958b5"
]
]
},
{
"id": "357518949dc85909",
"type": "junction",
"z": "503ae6a51f28e7b1",
"x": 240,
"y": 620,
"wires": [
[
"27049be02da427ed",
"f210817c6ad103fd",
"f79dc0217d77183f"
]
]
},
{
"id": "adf4bd06e9a983c8",
"type": "junction",
"z": "503ae6a51f28e7b1",
"x": 240,
"y": 380,
"wires": [
[
"76555f3a45184d26",
"3976c42cbd4334ce"
]
]
},
{
"id": "3fbfea693a42d5c4",
"type": "junction",
"z": "503ae6a51f28e7b1",
"x": 640,
"y": 180,
"wires": [
[
"82e5483fa9d750fd",
"251a52bf8516a9fb"
]
]
},
{
"id": "7a5c537d1408488e",
"type": "junction",
"z": "503ae6a51f28e7b1",
"x": 120,
"y": 380,
"wires": [
[
"adf4bd06e9a983c8",
"357518949dc85909",
"90184654071f780e"
]
]
},
{
"id": "90184654071f780e",
"type": "junction",
"z": "503ae6a51f28e7b1",
"x": 240,
"y": 820,
"wires": [
[
"82750e07d294a22f",
"c9d2ca3b6d642103"
]
]
},
{
"id": "61ed3bd3811096b7",
"type": "telegram sender",
"z": "503ae6a51f28e7b1",
"name": "Post Links",
"bot": "9fe44d40e8bd80ac",
"haserroroutput": false,
"outputs": 1,
"x": 730,
"y": 440,
"wires": [
[]
]
},
{
"id": "0949c2e6fce901db",
"type": "comment",
"z": "503ae6a51f28e7b1",
"name": "Discord Details",
"info": "REDACTED",
"x": 800,
"y": 60,
"wires": []
},
{
"id": "bc207948e399d00d",
"type": "python-function-ps",
"z": "503ae6a51f28e7b1",
"name": "Cohost Post Py",
"pythonPathType": "local",
"pythonPath": "python3",
"globalPythonName": "",
"importPathList": [],
"fnCodePre": "\n# user code here.\n",
"fnCode": "from cohost.models.user import User\nfrom cohost.models.block import AttachmentBlock, MarkdownBlock\n\nnode.log(\"PYTHON\")\nmsg[\"topic\"] = \"cohost\"\nuser = User.loginWithCookie(\"REDACTED\")\nproject = user.getProject(\"sciencegirl100\")\nblocks = [\n MarkdownBlock(msg[\"payload\"][\"desc\"])\n]\n\nfor i in range(len(msg[\"payload\"][\"files\"])):\n blocks = blocks + [AttachmentBlock(msg[\"payload\"][\"files\"][i][\"file\"], alt_text=msg[\"payload\"][\"images\"][i])]\n\nif msg[\"payload\"][\"spoil\"]:\n post = project.post(msg[\"payload\"][\"title\"], blocks, cws=msg[\"payload\"][\"seo\"], tags=msg[\"payload\"][\"seo\"])\nelse:\n post = project.post(msg[\"payload\"][\"title\"], blocks, tags=msg[\"payload\"][\"seo\"])\n\nmsg[\"payload\"] = post.url\nreturn msg\n",
"fnCodePost": "\n# user code here.\n",
"x": 400,
"y": 460,
"wires": [
[
"1a034ddb27d958b5"
]
]
},
{
"id": "953700757800ebd2",
"type": "comment",
"z": "503ae6a51f28e7b1",
"name": "Cohost Details",
"info": "https://github.com/valknight/cohost.py",
"x": 800,
"y": 100,
"wires": []
},
{
"id": "3976c42cbd4334ce",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Discord JS",
"func": "let channels = [\n [ \"REDACTED\", \"REDACTED\"]\n]\nlet run = async () => {\n const client = new discordUserBots.Client(\"REDACTED\")\n node.log({msg: \"Discord Init\"})\n client.on.ready = async () => {\n node.log({msg:\"Discord Client Logged In\"})\n let content = {\n content: `**${msg.payload.title}**\\n${msg.payload.desc}\\n#${msg.payload.seo.join(\" #\")}`,\n attachments: []\n }\n let images = msg.payload.files\n for (let i = 0; i < images.length; i++){\n let ext = images[i].file.replace(/^.*\\./, \"\")\n content.attachments.push({\n path: `/home/liz/.node-red/temp/crosspost/24/${images[i].file}`,\n name: `${msg.payload.spoil?\"SPOILER_\":\"\"}image_${i}.${ext}`,\n description: images[i].descr\n })\n }\n let links = [];\n for (let i = 0; i<channels.length; i++){\n let message = await client.send(channels[i][1], content)\n .catch(e => node.error(e))\n links.push(`https://discord.com/channels/${channels[i][0]}/${channels[i][1]}/${message.id}`)\n }\n msg.payload = links\n msg.topic = \"discord\"\n node.send(msg)\n node.done()\n }\n}\n\nrun()",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "discordUserBots",
"module": "discord-user-bots"
},
{
"var": "uuid",
"module": "uuid"
},
{
"var": "fs",
"module": "fs"
},
{
"var": "childProcess",
"module": "child_process"
}
],
"x": 390,
"y": 340,
"wires": [
[
"1a034ddb27d958b5"
]
]
},
{
"id": "981f827a7dc6659f",
"type": "comment",
"z": "503ae6a51f28e7b1",
"name": "Mastodon Details",
"info": "REDACTED",
"x": 800,
"y": 180,
"wires": []
},
{
"id": "cae4545707e742f4",
"type": "http in",
"z": "503ae6a51f28e7b1",
"name": "/post",
"url": "/post",
"method": "post",
"upload": true,
"swaggerDoc": "",
"x": 70,
"y": 40,
"wires": [
[
"5e011ac0717c733a",
"9acd68078c47fcde"
]
]
},
{
"id": "5e011ac0717c733a",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Request Authentication",
"func": "let error = null\nconst acceptedKey = [\n \"REDACTED\"\n]\nif (typeof msg.payload.key != 'string'){\n error = \"Missing Authentication\"\n}else {\n if (!acceptedKey.includes(msg.payload.key.toString(\"utf-8\"))){\n error = \"Invalid Authentication\"\n }\n}\n\nif (error) {\n if (msg.payload.key.toString()!=\"debug\"){\n msg.payload = error\n }\n return [ null, msg ]\n}else {\n return [ msg, null ]\n}",
"outputs": 2,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 210,
"y": 100,
"wires": [
[
"8175b77dc61e31ac"
],
[
"2d28ed050f457ff5",
"05bfe494ddc5ae1c"
]
]
},
{
"id": "8175b77dc61e31ac",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Payload Verification",
"func": "let error = null\nif (typeof msg.payload.images != 'string' ||\n typeof msg.payload.seo != 'string' ||\n typeof msg.payload.title != 'string' ||\n typeof msg.payload.desc != 'string'\n){\n error = \"Missing payload value\"\n} else {\n /* Expected Payload:\n {\n title: UTF-8 String,\n desc: UTF-8 String,\n seo: Array of UTF-8 Strings,\n images: Array of image alt text Strings\n }\n */\n try {\n let SPOIL = (typeof msg.payload.spoil != 'undefined')\n let imageDescriptions = []\n if ([...msg.payload.images.split(\";\")].length == msg.req.files.length){\n imageDescriptions = [...msg.payload.images.split(\";\")]\n }else if ([...msg.payload.images.split(\"\\n\")].length == msg.files.length){\n imageDescriptions = [...msg.payload.images.split(\"\\n\")]\n }else {\n node.warn({error: \"File Mismatch Conversion\", i: msg.payload.images, f:msg.req.files})\n error = \"Filedata Mismatch Conversion\"\n }\n msg.payload = {\n title: msg.payload.title,\n desc: msg.payload.desc,\n seo: [...msg.payload.seo.split(\";\")],\n images: imageDescriptions,\n spoil: SPOIL\n }\n if (msg.payload.images.length != msg.req.files.length){\n node.warn({error: \"File Mismatch\", i: msg.payload.images, f:msg.req.files})\n error = \"Filedata Mismatch\"\n }\n if (msg.payload.title.length + msg.payload.descr > 1900){\n error = \"Text Too Long\"\n }\n } catch(e) {\n error = \"Data Validation Error: \" + e.toString()\n }\n}\n\nif (error) {\n msg.payload = error\n return [ null, msg ]\n}else {\n return [ msg, null ]\n}\n",
"outputs": 2,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 80,
"wires": [
[
"3fbfea693a42d5c4"
],
[
"2d28ed050f457ff5"
]
]
},
{
"id": "251a52bf8516a9fb",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "API Response",
"func": "/*\n set msg.topic to the output type\nOutputs:\n - HTTP Response\n - Discord\n - Hackers.Town\n - Cohost\n - Instagram\n - Gemini Blog\n*/\n\n// HTTP API Response\nmsg.topic = \"http\"\nmsg.payload = \"Success\"\n\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 260,
"wires": [
[
"d93e3cd6bf6bbc6b"
]
]
},
{
"id": "2d28ed050f457ff5",
"type": "http response",
"z": "503ae6a51f28e7b1",
"name": "Error",
"statusCode": "401",
"headers": {},
"x": 490,
"y": 120,
"wires": []
},
{
"id": "9acd68078c47fcde",
"type": "debug",
"z": "503ae6a51f28e7b1",
"name": "Dump API Input",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 240,
"y": 40,
"wires": []
},
{
"id": "f552c81b990c1ded",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Assemble Links",
"func": "// node.warn(msg)\nlet payload = `${msg.req.body.title}\\n`\nfor (let k in msg.payload){\n if (k == \"discord\"){\n for (let y=0; y<msg.payload.discord.length; y++){\n payload += `${msg.payload.discord[y]}\\n`\n }\n }else{\n payload += `${msg.payload[k]}\\n`\n }\n}\nmsg.payload = {\n chatId: 1005895002,\n type: \"message\",\n content: payload\n};\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 720,
"y": 380,
"wires": [
[
"61ed3bd3811096b7",
"4e16d4b24f87bd40"
]
]
},
{
"id": "1a034ddb27d958b5",
"type": "join",
"z": "503ae6a51f28e7b1",
"name": "Aggregate Results",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "5",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 700,
"y": 340,
"wires": [
[
"f552c81b990c1ded",
"75b13d43522adb78"
]
]
},
{
"id": "d93e3cd6bf6bbc6b",
"type": "http response",
"z": "503ae6a51f28e7b1",
"name": "Return API",
"statusCode": "200",
"headers": {},
"x": 610,
"y": 260,
"wires": []
},
{
"id": "76555f3a45184d26",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Save Files",
"func": "let run = async () => {\n node.log({msg:\"Saving Attachments Locally for Cohost\"})\n let images = []\n for (let i = 0; i<msg.payload.images.length; i++){\n images.push({\n file: `/home/liz/.node-red/temp/crosspost/4/${msg.payload.files[i].file}`, \n descr: msg.payload.images[i]\n })\n }\n msg.payload.files = images\n node.send(msg)\n node.done()\n}\n\nrun()",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "uuid",
"module": "uuid"
},
{
"var": "fs",
"module": "fs"
},
{
"var": "childProcess",
"module": "child_process"
}
],
"x": 390,
"y": 420,
"wires": [
[
"bc207948e399d00d"
]
]
},
{
"id": "39f818538e39eb2d",
"type": "comment",
"z": "503ae6a51f28e7b1",
"name": "Master Plan 🌋",
"info": "Outputs:\n X HTTP Response\n X Discord\n X Hackers.Town\n X Cohost\n X Instagram\n X Gemini Blog\n \n \nTODO:\n * Discord support CW tags (seo)\n * use image rescale for all instead of each (large remodel)",
"x": 560,
"y": 40,
"wires": []
},
{
"id": "27049be02da427ed",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Instagram",
"func": "let run = async () => {\n node.log(\"Initialize Instagram API\")\n let ig = new instagramPrivateApi.IgApiClient()\n ig.state.generateDevice(env.get(\"IG_USERNAME\") + os.hostname());\n \n node.log(\"Instagram Log In\")\n // await ig.simulate.preLoginFlow()\n const user = await ig.account.login(env.get(\"IG_USERNAME\"), env.get(\"IG_PASSWORD\"))\n // await ig.simulate.postLoginFlow()\n \n node.log(\"Instagram Save Images Locally\")\n // let tempDir = \"/home/liz/.node-red/temp/instagram\"\n // if (!fs.existsSync(tempDir)){\n // node.log(\"Creating temp dir for Instagram\")\n // fs.mkdirSync(tempDir, {\n // recursive: true\n // })\n // }\n let albumImages = []\n for (let i = 0; i<msg.payload.images.length; i++){\n // let fileUUID = tempDir + \"/\" + uuid.v4() + \".\" + msg.req.files[i].originalname.replace(/^.*\\./, \"\")\n // fs.writeFileSync(fileUUID, msg.req.files[i].buffer)\n // if (Buffer.byteLength(msg.req.files[i].buffer) > 24000000){ // File is over 24MB\n // let resizeCMD = `/usr/bin/convert \"${fileUUID}\" -define jpeg:extent=30MB \"${fileUUID+\".jpeg\"}\"`\n // node.log(resizeCMD)\n // await childProcess.exec(resizeCMD, (err, stdo, stdi) => {\n // node.warn({msg: \"Instagram Resize\", err, stdo, stdi})\n // return;\n // })\n // fileUUID += \".jpeg\"\n // }\n // node.log({msg: \"Created \" + fileUUID})\n let filePath = `/home/liz/.node-red/temp/crosspost/4/${msg.payload.files[i].file}`\n node.log(`IG Append ${filePath}`)\n albumImages.push({\n file: fs.readFileSync(filePath)\n })\n }\n \n node.log(\"Instagram Sending Album\")\n let payload = {\n caption: `${msg.payload.title} - ${msg.payload.desc}`,\n items: albumImages\n }\n node.warn(payload)\n let result = null\n if (payload.items.length < 2){\n result = await ig.publish.photo({\n caption: payload.caption,\n file: payload.items[0].file\n })\n .catch(e => node.error(e))\n }else {\n result = await ig.publish.album(payload)\n .catch(e => node.error(e))\n }\n node.log(JSON.stringify(result))\n msg.topic = \"instagram\"\n msg.payload = \"\" //`https://www.instagram.com/p/${result.media.code}/` // might cause issues with multi-photo uploads\n node.send(msg)\n node.done()\n}\n\nrun()",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "instagramPrivateApi",
"module": "instagram-private-api"
},
{
"var": "os",
"module": "os"
},
{
"var": "fs",
"module": "fs"
},
{
"var": "uuid",
"module": "uuid"
},
{
"var": "childProcess",
"module": "child_process"
}
],
"x": 380,
"y": 540,
"wires": [
[
"dbbaebd1d08b6537"
]
]
},
{
"id": "bc5f12b832a7fadd",
"type": "comment",
"z": "503ae6a51f28e7b1",
"name": "Gemini Details",
"info": "\n/home/liz/public_gemini/images/UUID.EXT\n\n```\n# TITLE\n\nDESCR\n\n> #[TAGS]\n\n=> PHOTO ALT\n\n```\n\n/home/liz/public_gemini/blog/photos.gmi",
"x": 790,
"y": 140,
"wires": []
},
{
"id": "1e64b09285a83d77",
"type": "ssh-v3",
"z": "503ae6a51f28e7b1",
"name": "Prepend Photo File",
"conf": "6661ed2f46f73a90",
"debug": false,
"x": 730,
"y": 620,
"wires": [
[
"79d0b8d8b2235392"
]
]
},
{
"id": "5b520ce2508b2e19",
"type": "sftp in",
"z": "503ae6a51f28e7b1",
"sftp": "178ffcb2099210a1",
"operation": "put",
"filename": "",
"localFilename": "",
"fileContents": "",
"fileExtension": "",
"workdir": "/home/liz/public_gemini/images/",
"savedir": "/home/liz/public_gemini/images/",
"name": "Put Image",
"x": 810,
"y": 680,
"wires": [
[]
]
},
{
"id": "f210817c6ad103fd",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Gemini Blog",
"func": "/*\nOUTPUTS:\n - Link String * type\n - SSH command to prepend file\n - Array of SFTP objects\n*/\n\nlet run = async () => {\n let response = [\n ]\n let tags = \"#\" + msg.payload.seo.join(' #').replaceAll(\"'\", \"\\\\'\")\n // node.warn(msg.payload.seo.length)\n response[0] = \"gemini://gemini.hackers.town/liz/blog/photos.gmi\"\n msg.topic = \"gemini\"\n response[1] = `echo -e $'# ${msg.payload.title.replaceAll(\"'\", \"\\\\'\")}\\\\n\\\\n${msg.payload.desc.replace(\"'\", \"\\\\'\")}\\\\n\\\\n> ${tags}\\\\n\\\\n`\n response[2] = []\n \n node.log(\"Saving Attachments Locally for Gemini\")\n // Upload images to temp dir $HOME/.node-red/temp/discord/UUID.EXT\n // let tempDir = \"/home/liz/.node-red/temp/gemini\"\n // if (!fs.existsSync(tempDir)){\n // node.log({msg: \"Creating temp dir for Gemini\"})\n // fs.mkdirSync(tempDir, {\n // recursive: true\n // })\n // }\n for (let i = 0; i<msg.payload.images.length; i++){\n // let fileUUID = tempDir + \"/\" + uuid.v4() + \".\" + msg.req.files[i].originalname.replace(/^.*\\./, \"\")\n // fs.writeFileSync(fileUUID, msg.req.files[i].buffer)\n // if (Buffer.byteLength(msg.req.files[i].buffer) > 64000000){ // File is over 64MB\n // await childProcess.exec(`/usr/bin/convert \"${fileUUID}\" -define jpeg:extent=64MB \"${fileUUID+\".jpeg\"}\"`, (err, stdo, stdi) => {\n // return;\n // })\n // fileUUID += \".jpeg\"\n // }\n // node.log({msg: \"Created \" + fileUUID})\n let fileUUID = `/home/liz/.node-red/temp/crosspost/24/${msg.payload.files[i].file}`\n response[1] += `=> gemini://gemini.hackers.town/liz/images/${fileUUID.replace(/^.*\\//, \"\")} ${msg.payload.images[i]}\\\\n`.replaceAll(\"'\", \"\\\\'\")\n \n response[2].push({\n filename: \"/home/liz/public_gemini/images/\" + fileUUID.replace(/^.*\\//, \"\"),\n filedata: fs.readFileSync(fileUUID)\n })\n }\n response[1] += \"\\\\n' > /home/liz/public_gemini/photos.tmp; cat /home/liz/public_gemini/blog/photos.gmi >> /home/liz/public_gemini/photos.tmp; cat /home/liz/public_gemini/photos.tmp > /home/liz/public_gemini/blog/photos.gmi; rm /home/liz/public_gemini/photos.tmp\"\n // node.warn(response)\n node.send([{...msg, payload:response[0]}, {...msg, payload:response[1]}, {...msg, payload:response[2]}, ])\n node.done()\n}\n\nrun()",
"outputs": 3,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "fs",
"module": "fs"
},
{
"var": "uuid",
"module": "uuid"
},
{
"var": "childProcess",
"module": "child_process"
}
],
"x": 390,
"y": 700,
"wires": [
[
"dbbaebd1d08b6537"
],
[
"1e64b09285a83d77"
],
[
"94e42cfb52d1a60c"
]
]
},
{
"id": "94e42cfb52d1a60c",
"type": "split",
"z": "503ae6a51f28e7b1",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 650,
"y": 680,
"wires": [
[
"5b520ce2508b2e19"
]
]
},
{
"id": "f79dc0217d77183f",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Pixelfed",
"func": "const key = \"REDACTED\"\n\nlet run = async () => {\n node.log(\"Saving Attachments Locally for Pixelfed\")\n // Upload images to temp dir $HOME/.node-red/temp/discord/UUID.EXT\n // let tempDir = \"/home/liz/.node-red/temp/pixelfed\"\n // if (!fs.existsSync(tempDir)){\n // node.log(\"Creating temp dir for Pixelfed\")\n // fs.mkdirSync(tempDir, {\n // recursive: true\n // })\n // }\n let images = []\n for (let i = 0; i<msg.payload.images.length; i++){\n // let fileUUID = tempDir + \"/\" + uuid.v4() + \".\" + msg.req.files[i].originalname.replace(/^.*\\./, \"\")\n // fs.writeFileSync(fileUUID, msg.req.files[i].buffer)\n // if (Buffer.byteLength(msg.req.files[i].buffer) > 15000000){ // File is over 15MB (Pixelfed Limit)\n // node.warn({msg: \"Must convert image \", file: fileUUID})\n // await childProcess.exec(`/usr/bin/convert \"${fileUUID}\" -define jpeg:extent=15MB \"${fileUUID+\".jpeg\"}\"`, (err, stdo, stdi) => {\n // return;\n // })\n // fileUUID += \".jpeg\"\n // }\n // node.log(\"Created \" + fileUUID)\n let media = new formData()\n media.append(\"file\", fs.createReadStream(`/home/liz/.node-red/temp/crosspost/15/${msg.payload.files[i].file}`))\n media.append(\"description\", msg.payload.images[i])\n let resp = await axios.request({\n method: \"post\",\n url: \"https://pixel.maddie.info/api/v1/media\",\n headers: {\n \"Authorization\": `Bearer ${key}`,\n \"Content-Type\": \"multipart/form-data\"\n },\n data: media\n }).catch(e=>node.error(e))\n // node.warn({MediaID: resp.data.id})\n images.push(resp.data.id)\n }\n let data = {\n status: `${msg.payload.title}\\n${msg.payload.desc}`,\n visibility: \"public\",\n media_ids: images, // `${images.join(\",\")}`,\n sensitive: msg.payload.spoil\n }\n if (msg.payload.spoil){\n data.spoiler_text = msg.payload.seo.join(\", \")\n }\n // node.warn({d:data})\n let resp = await axios.request({\n method: \"post\",\n url: \"https://pixel.maddie.info/api/v1/statuses\",\n headers: {\n \"Authorization\": `Bearer ${key}`,\n \"Content-Type\": \"application/json\"\n },\n data: data\n }).catch(e=>node.error(e))\n // node.warn({resp:resp})\n msg.payload = resp.data.url\n msg.topic = \"pixelfed\"\n node.send(msg)\n node.done()\n}\n\nrun()",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "fs",
"module": "fs"
},
{
"var": "childProcess",
"module": "child_process"
},
{
"var": "uuid",
"module": "uuid"
},
{
"var": "axios",
"module": "axios"
},
{
"var": "formData",
"module": "form-data"
}
],
"x": 380,
"y": 620,
"wires": [
[
"dbbaebd1d08b6537"
]
]
},
{
"id": "79d0b8d8b2235392",
"type": "debug",
"z": "503ae6a51f28e7b1",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 770,
"y": 580,
"wires": []
},
{
"id": "75b13d43522adb78",
"type": "debug",
"z": "503ae6a51f28e7b1",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 870,
"y": 300,
"wires": []
},
{
"id": "05bfe494ddc5ae1c",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Debug layer",
"func": "msg.payload = {\n chatId: REDACTED,\n type: \"message\",\n conetent: JSON.stringify(msg.req.body)\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 250,
"y": 140,
"wires": [
[
"2ad8a1b0d62f3f26"
]
]
},
{
"id": "82e5483fa9d750fd",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Resize Images",
"func": "let run = async () => {\n let tempDir = \"/home/liz/.node-red/temp/crosspost\"\n let sizes = [4, 15, 24]\n for(let i=0; i<sizes.length; i++){\n if (!fs.existsSync(`${tempDir}/${sizes[i]}`)){\n node.log(`Creating temp dir for Images ${sizes[i]}`)\n fs.mkdirSync(`${tempDir}/${sizes[i]}`, {\n recursive: true\n })\n }\n }\n // 24MB Discord\n // 5MB Cohost\n // 24MB Instagram\n // 15MB Pixelfed\n // 24MB Gemini\n // 5 - 15 - 24\n let images = []\n for (let i = 0; i<msg.payload.images.length; i++){\n let fileUUID = uuid.v4() + \".\" + msg.req.files[i].originalname.replace(/^.*\\./, \"\")\n fs.writeFileSync(`${tempDir}/${fileUUID}`, msg.req.files[i].buffer)\n for (let y=0; y<sizes.length; y++){\n let fullName = `${tempDir}/${sizes[y]}/${fileUUID}`\n await childProcess.execSync(`/usr/bin/convert \"${tempDir}/${fileUUID}\" -define jpeg:extent=${sizes[y]}MB \"${fullName}\"`)\n node.log({msg: \"Created \" + fullName})\n }\n \n images.push({\n file: fileUUID, \n descr: msg.payload.images[i]\n })\n }\n node.log(\"CONVERSION COMPLETE\")\n msg.payload.files = images\n node.send(msg)\n node.done()\n}\n\n\nrun()",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "fs",
"module": "fs"
},
{
"var": "childProcess",
"module": "child_process"
},
{
"var": "uuid",
"module": "uuid"
}
],
"x": 120,
"y": 260,
"wires": [
[
"7a5c537d1408488e"
]
]
},
{
"id": "4e16d4b24f87bd40",
"type": "olfnf-folder-operations",
"z": "503ae6a51f28e7b1",
"operation": "remove",
"folder": "/home/liz/.node-red/temp/crosspost",
"folder_type": "str",
"recursive": true,
"name": "Remove Temp Dir",
"x": 930,
"y": 380,
"wires": [
[]
]
},
{
"id": "08692e5a11d876cb",
"type": "comment",
"z": "503ae6a51f28e7b1",
"name": "Unsplash Details",
"info": "",
"x": 560,
"y": 780,
"wires": []
},
{
"id": "c1b0c978b8e7dbe9",
"type": "comment",
"z": "503ae6a51f28e7b1",
"name": "Tumblr Details",
"info": "",
"x": 550,
"y": 860,
"wires": []
},
{
"id": "c9d2ca3b6d642103",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Tumblr",
"func": "\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [
{
"var": "fs",
"module": "fs"
},
{
"var": "tumblrJs",
"module": "tumblr.js"
}
],
"x": 370,
"y": 860,
"wires": [
[]
]
},
{
"id": "82750e07d294a22f",
"type": "function",
"z": "503ae6a51f28e7b1",
"name": "Unsplash",
"func": "\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 380,
"y": 780,
"wires": [
[]
]
},
{
"id": "2ad8a1b0d62f3f26",
"type": "telegram sender",
"z": "503ae6a51f28e7b1",
"name": "Post Debug Data",
"bot": "9fe44d40e8bd80ac",
"haserroroutput": false,
"outputs": 1,
"x": 450,
"y": 180,
"wires": [
[]
]
},
{
"id": "9fe44d40e8bd80ac",
"type": "telegram bot",
"botname": "cross_liz_bot",
"usernames": "",
"chatids": "",
"baseapiurl": "",
"updatemode": "polling",
"pollinterval": "300",
"usesocks": false,
"sockshost": "",
"socksprotocol": "socks5",
"socksport": "6667",
"socksusername": "anonymous",
"sockspassword": "",
"bothost": "",
"botpath": "",
"localbotport": "8443",
"publicbotport": "8443",
"privatekey": "",
"certificate": "",
"useselfsignedcertificate": false,
"sslterminated": false,
"verboselogging": false
},
{
"id": "6661ed2f46f73a90",
"type": "ssh-conf",
"ssh": "REDACTED",
"name": "HacktsTown",
"userlabel": "HacktsTown"
},
{
"id": "178ffcb2099210a1",
"type": "sftp",
"host": "tty.hackers.town",
"port": "22",
"username": "liz",
"password": "",
"sshkey": "REDACTED",
"hmac": [
"hmac-sha2-512-96"
],
"cipher": [
"aes256-gcm@openssh.com"
]
}
]