From bd94626b10b6422830f8be5e161cd7b9e6db2da8 Mon Sep 17 00:00:00 2001 From: matu6968 Date: Sun, 10 Nov 2024 23:48:49 +0100 Subject: [PATCH] Add To view a app file --- To-view-a-app-file.md | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 To-view-a-app-file.md diff --git a/To-view-a-app-file.md b/To-view-a-app-file.md new file mode 100644 index 0000000..267dab6 --- /dev/null +++ b/To-view-a-app-file.md @@ -0,0 +1,74 @@ +# To view a app file: + +## HTTP request type: `GET` + +## Authorization required: No + +## Endpoint: `/uploads/[app_name]/index.js` + +### Output: + +If it does exist: +``` +let installcamera = { + runs: true, + name: 'Camera', + ver: 6.0, + init: async function () { + const win = tk.mbw('Camera', '380px', 'auto', true, undefined, undefined); + const cam = tk.c('video', win.main, 'embed'); + cam.autoplay = true; + cam.playsInline = true; + if (navigator.mediaDevices.getUserMedia) { + navigator.mediaDevices.getUserMedia({ video: true }) + .then(function (stream) { + cam.srcObject = stream; + cam.onloadedmetadata = function () { + cam.play(); + }; + }) + .catch(function (error) { + wm.notif(`Something went wrong. Make sure that WebDesk has camera permissions.`, 'Click "Open" to view error details"', () => wm.notif('Camera error details', error)); + }); + } + async function save() { + let canvas = document.createElement('canvas'); + canvas.width = cam.videoWidth; + canvas.height = cam.videoHeight; + var context = canvas.getContext('2d'); + context.drawImage(cam, 0, 0, canvas.width, canvas.height); + const silly = canvas.toDataURL('image/png'); + const num = gen(7); + const bruh = `Capture ${num}.png`; + const wowzers = `/user/files/${bruh}`; + await fs.write(wowzers, silly); + wm.notif('Saved picture!', `Path: ${wowzers}`, () => app.imgview.init(silly)); + } + function nocam() { + var tracks = cam.srcObject.getTracks(); + tracks.forEach(function (track) { + track.stop(); + }); + cam.srcObject = null; + } + win.closebtn.addEventListener('mousedown', function () { + nocam(); + }); + tk.cb('b1', 'Capture', function () { + save(); + }, win.main); + } +} + +app['734017834573'] = installcamera; +installcamera = undefined; + + +Status code: 200 +``` +Otherwaise if it does not exist: +``` +404 page not found + +Status code: 404 +``` \ No newline at end of file