Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

A super cool zoom machine #686

Merged
merged 24 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f67e4b9
feat: a very cool zoomy thing, pc only :(
TacticalTechJay Feb 7, 2025
9edb38f
fix: a sort of 404 for when dev'ing cuz next didn't care to compile t…
TacticalTechJay Feb 7, 2025
7ef2082
fix: at least check the password before anything else >:(
TacticalTechJay Feb 7, 2025
942dbd3
fix: just in case someone goes /upload(or /url)/dashboard
TacticalTechJay Feb 7, 2025
13826d0
fix: whoopsids
TacticalTechJay Feb 7, 2025
17872c9
fix: size can be null if it doesn't exist
TacticalTechJay Feb 7, 2025
8439fac
fix: sometimes it doesn't exists, oops
TacticalTechJay Feb 7, 2025
e02a644
notFix: force delete to avoid error
TacticalTechJay Feb 7, 2025
8f9731e
feat: Do we really overcomplicate things? Added passwordy thingy to r…
TacticalTechJay Feb 7, 2025
6559055
ack, message fix
TacticalTechJay Feb 7, 2025
b6898b0
facepalm
TacticalTechJay Feb 7, 2025
b8e29fe
fix: it's a little shorter, didn't realize this works too
TacticalTechJay Feb 7, 2025
d63a64c
there wasn't an export const config for this one
TacticalTechJay Feb 8, 2025
13bc033
got thumbnails working again :D
TacticalTechJay Feb 8, 2025
ea6118f
ugh fiiine
TacticalTechJay Feb 8, 2025
b9a8029
no more repeat thumbnail generations >:(
TacticalTechJay Feb 8, 2025
d26cdb4
bump fastify
TacticalTechJay Feb 11, 2025
ad2ba18
pass queries too
TacticalTechJay Feb 11, 2025
9c4bb02
add thumbnail for type
TacticalTechJay Feb 11, 2025
233324b
notFeat: Don't expect much from this added route, I won't add more th…
TacticalTechJay Feb 12, 2025
c8b340c
fix: my own mistake of breaking embeds with sites. Images should have…
TacticalTechJay Feb 12, 2025
b83ca16
fix: any edge case where thumbnail don't exist
TacticalTechJay Feb 12, 2025
66da8b8
fix??: I unno, discord hasn't embedded without the link showing but m…
TacticalTechJay Feb 12, 2025
201d4b6
chore: some trimming that I could
TacticalTechJay Feb 12, 2025
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
2 changes: 1 addition & 1 deletion src/lib/datasources/Local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Local extends Datasource {
}

public async delete(file: string): Promise<void> {
await rm(join(this.path, file));
await rm(join(this.path, file), { force: true });
}

public async clear(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datasources/S3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class S3 extends Datasource {
}

public async delete(file: string): Promise<void> {
await this.s3.removeObject(this.config.bucket, file);
await this.s3.removeObject(this.config.bucket, file, { forceDelete: true });
}

public async clear(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { bytesToHuman } from './bytes';
import Logger from 'lib/logger';

export type ParseValue = {
file?: File;
file?: Omit<Partial<File>, 'password'>;
url?: Url;
user?: User;

Expand Down
40 changes: 0 additions & 40 deletions src/pages/api/auth/file.ts

This file was deleted.

75 changes: 75 additions & 0 deletions src/pages/api/oembed/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { NextApiReq, NextApiRes, withZipline } from 'middleware/withZipline';
import 'lib/prisma';
import 'lib/config';

async function handler(req: NextApiReq, res: NextApiRes) {
const { id } = req.query as { id: string };
if (req.method === 'GET') {
if (!id || isNaN(parseInt(id))) return res.badRequest('no id');

const file = await prisma.file.findUnique({
where: {
id: parseInt(id),
},
include: {
thumbnail: {
select: {
name: true,
},
},
user: {
select: {
username: true,
},
},
},
});
if (!file || !!file.password) return res.notFound('no such file exists');

const mediaType: 'image' | 'video' | 'audio' | 'other' =
(new RegExp(/^(?<type>image|video|audio)/).exec(file.mimetype)?.groups?.type as
| 'image'
| 'video'
| 'audio') || 'other';

let host = req.headers.host;
const proto = req.headers['x-forwarded-proto'];
try {
if (
JSON.parse(req.headers['cf-visitor'] as string).scheme === 'https' ||
proto === 'https' ||
config.core.return_https
)
host = `https://${host}`;
else host = `http://${host}`;
} catch (e) {
if (proto === 'https' || config.core.return_https) host = `https://${host}`;
else host = `http://${host}`;
}

if (mediaType === 'image')
return res.json({
type: 'photo',
version: '1.0',
url: `${host}/r/${file.name}`,
});
if (mediaType === 'video')
return res.json({
type: 'video',
version: '1.0',
url: `${host}/r/${file.name}`,
thumbnail_url: file.thumbnail ? `${host}/r/${file.thumbnail?.name}` : undefined,
html: `<video><source src="${host}/r/${file.name}" type="${file.mimetype}"/></video>`,
});
return res.json({
type: 'link',
version: '1.0',
url: `${host}${config.uploader.route}/${file.name}`,
});
}
}

export default withZipline(handler, {
methods: ['GET'],
user: false,
});
Loading