Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: allow using the generated ID in the web viewer (#181) #186

Merged
merged 2 commits into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/generators/zws.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import lengthGen from './lengthGen';
const zeroWidthChars = ['\u200B', '\u200C', '\u200D', '\u2060'];
export default ({ length }: { length: number }) => lengthGen(length, zeroWidthChars);
export const checkIfZws = (str: string) => str.split('').every(char => zeroWidthChars.includes(char));
5 changes: 3 additions & 2 deletions src/routers/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ 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, useSia }: Config = fs.readJsonSync(path('config.json'));
const { diskFilePath, s3enabled, viewDirect, useIdInViewer, idInViewerExtension, useSia }: 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';
Expand Down Expand Up @@ -47,7 +48,7 @@ router.get('/', (req: Request, res: Response, next) => data().get(req.ass.resour
// Send the view to the client
res.render('view', {
fileIs: fileData.is,
title: escape(fileData.originalname),
title: useIdInViewer && !checkIfZws(resourceId) ? `${resourceId}${idInViewerExtension ? `${fileData.ext}` : ''}` : escape(fileData.originalname),
mimetype: fileData.mimetype,
uploader: users.find(user => user.unid === fileData.uploader)?.username || 'Unknown',
timestamp: formatTimestamp(fileData.timestamp, fileData.timeoffset),
Expand Down
14 changes: 14 additions & 0 deletions src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const config = {
spaceReplace: '_',
mediaStrict: false,
viewDirect: false,
useIdInViewer: false,
idInViewerExtension: false,
dataEngine: '@tycrek/papito',
frontendName: 'ass-x',
useSia: false,
Expand Down Expand Up @@ -168,6 +170,18 @@ function doSetup() {
default: config.viewDirect,
required: false
},
useIdInViewer: {
description: 'Use the ID in the web viewer instead of the filename',
type: 'boolean',
default: config.useIdInViewer,
required: false
},
idInViewerExtension: {
description: '(Only applies if "useIdInViewer" is true) Include the file extension in the ID in the web viewer',
type: 'boolean',
default: config.idInViewerExtension,
required: false
},
dataEngine: {
description: 'Data engine to use (must match an npm package name. If unsure, leave blank)',
type: 'string',
Expand Down
2 changes: 2 additions & 0 deletions src/types/json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ declare module 'ass-json' {
gfyIdSize: number
mediaStrict: boolean
viewDirect: boolean
useIdInViewer: boolean
idInViewerExtension: boolean
dataEngine: string
frontendName: string
indexFile: string
Expand Down