From 95339688d28c38568abe6cc35ffdc17c9ac5741f Mon Sep 17 00:00:00 2001 From: tycrek Date: Mon, 26 Dec 2022 14:51:22 -0700 Subject: [PATCH] remove: Sia Skynet is no longer usable --- .github/README.md | 15 +-------------- package-lock.json | 1 - package.json | 1 - src/ass.ts | 4 ++-- src/routers/resource.ts | 10 +++------- src/setup.js | 8 +------- src/skynet.ts | 37 ------------------------------------- src/storage.ts | 12 +++--------- src/types/json.d.ts | 1 - 9 files changed, 10 insertions(+), 79 deletions(-) delete mode 100644 src/skynet.ts diff --git a/.github/README.md b/.github/README.md index 6f76bc2..0764962 100644 --- a/.github/README.md +++ b/.github/README.md @@ -72,8 +72,7 @@ ass was designed with developers in mind. If you are a developer & want somethin - Run locally or in a Docker container - **Multiple file storage methods** - Local file system - - Amazon S3, including [DigitalOcean Spaces] - - [Skynet] (free decentralized storage on the [Sia] blockchain) + - Amazon S3, including [DigitalOcean Spaces] (more coming soon) - **Multiple data storage methods** using [data engines] - **File** - JSON (default, [papito]) @@ -86,8 +85,6 @@ ass was designed with developers in mind. If you are a developer & want somethin [Git Submodules]: https://git-scm.com/book/en/v2/Git-Tools-Submodules [ZWS]: https://zws.im [DigitalOcean Spaces]: https://www.digitalocean.com/products/spaces/ -[Skynet]: https://siasky.net/ -[Sia]: https://sia.tech/ [data engines]: #data-engines [papito]: https://github.com/tycrek/papito [ass-psql]: https://github.com/tycrek/ass-psql @@ -346,16 +343,6 @@ Any existing object storage server that's compatible with [Amazon S3] can be use S3 servers are generally very fast & have very good uptime, though this will depend on the hosting provider & plan you choose. -### Skynet - -**As of August 12, 2022, [Skynet Labs is shut down].** Skynet *will continue to work*, as such is the nature of decentralized services. - -[Skynet] is a decentralized CDN created by [Skynet Labs]. It utilizes the [Sia] blockchain, the leading decentralized cloud storage platform, which boasts "no signups, no servers, no trusted third parties". For hosts who are looking for a reliable, always available storage solution with lots of capacity & no costs, Skynet may be your best option. However, uploads tend to be on the slower side (though speeds will improve as the Sia network grows). - -[Skynet Labs is shut down]: https://skynetlabs.com/news/skynet-labs-shutting-down-skynet-remains-online -[Amazon S3]: https://en.wikipedia.org/wiki/Amazon_S3 -[Skynet Labs]: https://github.com/SkynetLabs - ## New user system (v0.14.0) The user system was overhauled in v0.14.0 to allow more features and flexibility. New fields on users include `admin`, `passhash`, `unid`, and `meta` (these will be documented more once the system is finalized). diff --git a/package-lock.json b/package-lock.json index f9a8d35..1a9fce4 100755 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "0.14.0-alpha.1", "license": "ISC", "dependencies": { - "@skynetlabs/skynet-nodejs": "^2.3.0", "@tsconfig/node16": "^1.0.1", "@tycrek/discord-hookr": "^0.1.0", "@tycrek/express-nofavicon": "^1.0.3", diff --git a/package.json b/package.json index 6c78ad0..986841a 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "url": "https://patreon.com/tycrek" }, "dependencies": { - "@skynetlabs/skynet-nodejs": "^2.3.0", "@tsconfig/node16": "^1.0.1", "@tycrek/discord-hookr": "^0.1.0", "@tycrek/express-nofavicon": "^1.0.3", diff --git a/src/ass.ts b/src/ass.ts index 097812f..101ede6 100644 --- a/src/ass.ts +++ b/src/ass.ts @@ -24,7 +24,7 @@ if (!fs.existsSync(configPath) || fs.readFileSync(configPath).toString().length //#endregion // Load the JSON -const { host, port, useSsl, isProxied, s3enabled, frontendName, useSia, diskFilePath }: Config = fs.readJsonSync(path('config.json')); +const { host, port, useSsl, isProxied, s3enabled, frontendName, diskFilePath }: Config = fs.readJsonSync(path('config.json')); const { CODE_INTERNAL_SERVER_ERROR }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); const { name, version, homepage }: Package = fs.readJsonSync(path('package.json')); @@ -142,5 +142,5 @@ app.use((err: ErrWrap, _req: Request, res: Response) => log.error(err.message).e .info('Frontend', ASS_FRONTEND.enabled ? ASS_FRONTEND.brand : 'disabled', `${ASS_FRONTEND.enabled ? `${getTrueHttp()}${getTrueDomain()}${ASS_FRONTEND.endpoint}` : ''}`) .info('Custom index', ASS_INDEX ?? 'disabled') .blank() - .express()!.Host(app, port, host, () => log.success('Ready for uploads', `Storing resources ${s3enabled ? 'in S3' : useSia ? 'on Sia blockchain' : 'on disk'}`)); + .express()!.Host(app, port, host, () => log.success('Ready for uploads', `Storing resources ${s3enabled ? 'in S3' : 'on disk'}`)); })(); diff --git a/src/routers/resource.ts b/src/routers/resource.ts index 7b60d76..94fbc58 100644 --- a/src/routers/resource.ts +++ b/src/routers/resource.ts @@ -6,10 +6,9 @@ import escape from 'escape-html'; import fetch, { Response as FetchResponse } from 'node-fetch'; import { Request, Response } from 'express'; import { deleteS3 } from '../storage'; -import { SkynetDelete, SkynetDownload } from '../skynet'; import { checkIfZws } from '../generators/zws'; import { path, log, getTrueHttp, getTrueDomain, formatBytes, formatTimestamp, getS3url, getDirectUrl, getResourceColor, replaceholder } from '../utils'; -const { diskFilePath, s3enabled, viewDirect, useIdInViewer, idInViewerExtension, useSia }: Config = fs.readJsonSync(path('config.json')); +const { diskFilePath, s3enabled, viewDirect, useIdInViewer, idInViewerExtension }: Config = fs.readJsonSync(path('config.json')); const { CODE_UNAUTHORIZED, CODE_NOT_FOUND, }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); import { data } from '../data'; import { users } from '../auth'; @@ -96,9 +95,6 @@ router.get('/direct*', (req: Request, res: Response, next) => data().get(req.ass file.headers.forEach((value, header) => res.setHeader(header, value)); file.body?.pipe(res); }), - sia: () => SkynetDownload(fileData) - .then((stream) => stream.pipe(res)) - .then(() => SkynetDelete(fileData)), local: () => fs.pathExists(path(fileData.path)) .then((exists) => new Promise((resolve, reject) => !exists ? reject(new Error('File does not exist')) @@ -108,7 +104,7 @@ router.get('/direct*', (req: Request, res: Response, next) => data().get(req.ass .sendFile(path(fileData.path), (err) => err ? reject(err) : resolve(void 0)))) }; - return uploaders[fileData.randomId.startsWith('sia://') ? 'sia' : s3enabled ? 's3' : 'local'](); + return uploaders[s3enabled ? 's3' : 'local'](); }).catch(next)); // Thumbnail response @@ -155,7 +151,7 @@ router.get('/delete/:deleteId', (req: Request, res: Response, next) => { // Save the file information return Promise.all([ - s3enabled ? deleteS3(fileData) : !useSia ? fs.rmSync(path(fileData.path)) : () => Promise.resolve(), + s3enabled ? deleteS3(fileData) : fs.rmSync(path(fileData.path)), (!fileData.is || (fileData.is.image || fileData.is.video)) && fs.existsSync(path(diskFilePath, 'thumbnails/', fileData.thumbnail)) ? fs.rmSync(path(diskFilePath, 'thumbnails/', fileData.thumbnail)) : () => Promise.resolve()]); }) diff --git a/src/setup.js b/src/setup.js index 2c9c076..211af5b 100644 --- a/src/setup.js +++ b/src/setup.js @@ -16,7 +16,6 @@ const config = { idInViewerExtension: false, dataEngine: '@tycrek/papito', frontendName: 'ass-x', - useSia: false, savePerDay: false, adminWebhookEnabled: false, s3enabled: false, @@ -47,6 +46,7 @@ const oldConfig = { diskFilePath: 'uploads/', saveWithDate: true, // Some systems don't like dirs with massive amounts of files saveAsOriginal: false, // Prone to conflicts, which ass doesn't handle + useSia: false, // Sia has been shut down in 2022, uploads fail as of 2022-12-26 }; function getConfirmSchema(description) { @@ -195,12 +195,6 @@ function doSetup() { default: config.frontendName, required: false }, - useSia: { - description: 'Use Sia Skynet for decentralized file storage?', - type: 'boolean', - default: config.useSia, - required: false - }, savePerDay: { description: 'Save uploads in folders by day (YYYY-MM-DD) instead of by month (YYYY-MM)', type: 'boolean', diff --git a/src/skynet.ts b/src/skynet.ts deleted file mode 100644 index b6f1cb2..0000000 --- a/src/skynet.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { FileData } from './types/definitions'; -import fs, { ReadStream } from 'fs-extra'; -import { path } from './utils'; -import { SkynetClient } from '@skynetlabs/skynet-nodejs'; - -function getFullPath(fileData: FileData) { - return path('share', '.skynet', `${fileData.randomId}${fileData.ext}`.replace(/sia\:\/\//gi, '')); -} - -// Create the SkyNet client -export const Skynet = new SkynetClient(); - -export function SkynetUpload(path: string): Promise { - return new Promise(async (resolve, reject) => { - try { - const skylink = await Skynet.uploadFile(path); - resolve(skylink); - } catch (error) { - reject(error); - } - }); -} - -export function SkynetDownload(fileData: FileData): Promise { - return new Promise((resolve: Function, reject) => - fs.ensureDir(path('share', '.skynet')) - .then(async () => { - await Skynet.downloadFile(getFullPath(fileData), fileData.randomId); - return fs.createReadStream(getFullPath(fileData)) - }) - .then((stream) => resolve(stream)) - .catch(reject)); -} - -export function SkynetDelete(fileData: FileData) { - return fs.remove(getFullPath(fileData)); -} diff --git a/src/storage.ts b/src/storage.ts index 563d0e1..869ae47 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -9,10 +9,9 @@ import Thumbnail from './thumbnails'; import Vibrant from './vibrant'; import Hash from './hash'; import { path, generateId, log } from './utils'; -import { SkynetUpload } from './skynet'; import { Request, Response } from 'express'; import { removeGPS } from './nightmare'; -const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, diskFilePath, saveAsOriginal, saveWithDate, savePerDay, mediaStrict, maxUploadSize, useSia }: Config = fs.readJsonSync(path('config.json')); +const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, diskFilePath, saveAsOriginal, saveWithDate, savePerDay, mediaStrict, maxUploadSize }: Config = fs.readJsonSync(path('config.json')); const { CODE_UNSUPPORTED_MEDIA_TYPE }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); const ID_GEN_LENGTH = 32; @@ -129,7 +128,7 @@ export function processUploaded(req: Request, res: Response, next: Function) { / .catch((err) => log.debug('!! EXIF GPS data could not be removed', err)) // Save file - .then(() => log.debug('Saving file', req.file.originalname, s3enabled ? 'in S3' : useSia ? 'on Sia blockchain' : 'on disk')) + .then(() => log.debug('Saving file', req.file.originalname, s3enabled ? 'in S3' : 'on disk')) .then(() => // skipcq: JS-0229 new Promise((resolve, reject) => { @@ -143,18 +142,13 @@ export function processUploaded(req: Request, res: Response, next: Function) { / Body: fs.createReadStream(req.file.path) }).promise().then(resolve).catch(reject); - // Use Sia Skynet - else if (useSia) return SkynetUpload(req.file.path) - .then((skylink) => req.file.randomId = skylink) - .then(resolve).catch(reject); - // Save to local storage else return fs.ensureDir(getDatedDirname()) .then(() => tempFileName = getLocalFilename(req)) .then(() => fs.copy(req.file.path, tempFileName, { preserveTimestamps: true })) .then(resolve).catch(reject); })) - .then(() => log.debug('File saved', req.file.originalname, s3enabled ? 'in S3' : useSia ? 'on Sia blockchain' : 'on disk')) + .then(() => log.debug('File saved', req.file.originalname, s3enabled ? 'in S3' : 'on disk')) .catch((err) => next(err)) // Delete the file diff --git a/src/types/json.d.ts b/src/types/json.d.ts index d6664de..bf54ade 100644 --- a/src/types/json.d.ts +++ b/src/types/json.d.ts @@ -17,7 +17,6 @@ declare module 'ass-json' { dataEngine: string frontendName: string indexFile: string - useSia: boolean savePerDay: boolean adminWebhookEnabled: boolean adminWebhookUrl: string