diff --git a/src/auth.ts b/src/auth.ts index 4241e2d..2c83dc8 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -3,11 +3,13 @@ */ import fs from 'fs-extra'; -import { log, path, arrayEquals } from './utils'; import { nanoid } from 'nanoid'; -import { User, Users, OldUsers } from './types/auth'; import { Request } from 'express'; import bcrypt from 'bcrypt'; +import { log, path, arrayEquals } from './utils'; +import { data } from './data'; +import { User, Users, OldUsers } from './types/auth'; +import { FileData } from './types/definitions'; const SALT_ROUNDS = 10; diff --git a/src/routers/resource.ts b/src/routers/resource.ts index d42c7b0..aee06d3 100644 --- a/src/routers/resource.ts +++ b/src/routers/resource.ts @@ -11,7 +11,7 @@ import { path, log, getTrueHttp, getTrueDomain, formatBytes, formatTimestamp, ge const { diskFilePath, s3enabled, viewDirect, useSia }: Config = fs.readJsonSync(path('config.json')); const { CODE_UNAUTHORIZED, CODE_NOT_FOUND, }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json')); import { data } from '../data'; -import { findFromToken } from '../auth'; +import { users } from '../auth'; import express from 'express'; const router = express.Router(); @@ -49,7 +49,7 @@ router.get('/', (req: Request, res: Response, next) => data().get(req.ass.resour fileIs: fileData.is, title: escape(fileData.originalname), mimetype: fileData.mimetype, - uploader: findFromToken(fileData.token)?.username ?? 'Unknown', + uploader: users.find(user => user.unid === fileData.uploader)?.username || 'Unknown', timestamp: formatTimestamp(fileData.timestamp, fileData.timeoffset), size: formatBytes(fileData.size), // todo: figure out how to not ignore this diff --git a/src/routers/upload.ts b/src/routers/upload.ts index 01632d6..be89389 100644 --- a/src/routers/upload.ts +++ b/src/routers/upload.ts @@ -60,7 +60,7 @@ router.post('/', (req: Request, res: Response, next: Function) => { req.file!.timeoffset = req.headers['x-ass-timeoffset']?.toString() || 'UTC+0'; // Keep track of the token that uploaded the resource - req.file.token = req.token ?? ''; + req.file.uploader = findFromToken(req.token)?.unid ?? ''; // Attach any embed overrides, if necessary req.file.opengraph = { diff --git a/src/types/definitions.d.ts b/src/types/definitions.d.ts index 5628869..cbbdfbf 100644 --- a/src/types/definitions.d.ts +++ b/src/types/definitions.d.ts @@ -38,7 +38,11 @@ export interface FileData { domain: string timestamp: number timeoffset: string - token: string + /** + * @deprecated + */ + token?: string + uploader: string opengraph: OpenGraphData // I found this in utils and idk where it comes from