Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
fix: incorrect protocol bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsKoud committed Oct 16, 2023
1 parent c96b591 commit 0d3a72b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/routes/api/v1/bins/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class ApiRoute extends Route<Server> {

domain.auditlogs.register("Pastebin Created", `Id: ${id}`);
res.status(200).json({
url: `${req.protocol}://${domain}/bins/${id}`,
url: `${Utils.getProtocol()}${domain}/bins/${id}`,
visible: pastebin.visible,
password: Boolean(pastebin.password),
highlight: pastebin.highlight,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/routes/api/v1/upload/chunk/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class ApiRoute extends Route<Server> {
domain.partialFileManager.partials.delete(body.id);
await this.server.prisma.partialFile.delete({ where: { path: partialFileHandler.path } });

res.status(200).send({ status: "FINISHED", url: `${req.protocol}://${domain.domain}/files/${partialFileHandler.documentId}` });
res.status(200).send({ status: "FINISHED", url: `${Utils.getProtocol()}${domain.domain}/files/${partialFileHandler.documentId}` });
}

/**
Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/routes/api/v1/upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type Domain from "#components/Domain.js";
import { Auth } from "#lib/Auth.js";
import { Utils } from "#lib/utils.js";
import type Server from "#server.js";
import { ApplyOptions, Route, methods } from "@snowcrystals/highway";
import type { NextFunction, Request, Response } from "express";
Expand Down Expand Up @@ -35,7 +36,7 @@ export default class ApiRoute extends Route<Server> {
const uploadConfig = this.parseFields(fields);
if (uploadedFiles.length === 1) {
const file = await domain.registerFile(uploadedFiles[0], uploadConfig);
const fileUrl = `${req.protocol}://${domain}/files/${file}`;
const fileUrl = `${Utils.getProtocol()}${domain}/files/${file}`;
res.send({ url: fileUrl, files: { [uploadedFiles[0].originalFilename!]: fileUrl } });
return;
}
Expand All @@ -49,7 +50,7 @@ export default class ApiRoute extends Route<Server> {
res.send({
url: registedFiles[0].url,
files: registedFiles
.map((file) => ({ [file.name]: `${req.protocol}://${domain}/files/${file.url}` }))
.map((file) => ({ [file.name]: `${Utils.getProtocol()}${domain}/files/${file.url}` }))
.reduce((a, b) => ({ ...a, ...b }), {})
});
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/routes/api/v1/urls/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ApiRoute extends Route<Server> {
const url = await this.server.prisma.url.create({
data: { date: new Date(), url: body.url, id: path, visible: body.visible, domain: domain.domain }
});
res.send({ url: `${req.protocol}://${domain.domain}/r/${path}`, date: url.date, visible: url.visible });
res.send({ url: `${Utils.getProtocol()}${domain.domain}/r/${path}`, date: url.date, visible: url.visible });
} catch (err) {
this.server.logger.fatal("[URL:CREATE]: Fatal error while creating a shorturl", err);
res.status(500).send({
Expand Down
10 changes: 5 additions & 5 deletions apps/server/src/trpc/v1/dashboard/bins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const binsRoute = t.router({
})
).query(async (opt) => {
const { query, page, sort } = opt.input;
const { domain, server, req } = opt.ctx;
const { domain, server } = opt.ctx;

let entries = await server.prisma.pastebin.findMany({ where: { domain: domain.domain } });

Expand All @@ -39,7 +39,7 @@ export const binsRoute = t.router({
highlight: bin.highlight,
views: bin.views,
visible: bin.visible,
url: `${req.protocol}://${domain}/bins/${bin.id}`
url: `${Utils.getProtocol()}${domain}/bins/${bin.id}`
}));

return {
Expand Down Expand Up @@ -74,7 +74,7 @@ export const binsRoute = t.router({
visible: z.boolean(),
passwordEnabled: z.boolean(),
password: z.string().optional(),
data: z.string().nonempty("Pastebin content is required"),
data: z.string().min(1, "Pastebin content is required"),
highlight: z.string({ required_error: "A valid highlight type is required" })
})
).mutation(async (opt) => {
Expand Down Expand Up @@ -116,7 +116,7 @@ export const binsRoute = t.router({
})
).mutation(async (opt) => {
const { name, visible, password, data, highlight } = opt.input;
const { server, domain, req } = opt.ctx;
const { server, domain } = opt.ctx;

const config = Config.getEnv();
const pastebins = await server.prisma.pastebin.findMany({ where: { domain: domain.domain } });
Expand Down Expand Up @@ -145,7 +145,7 @@ export const binsRoute = t.router({

domain.auditlogs.register("Pastebin Created", `Id: ${id}`);

return `${req.protocol}://${domain}/bins/${id}`;
return `${Utils.getProtocol()}${domain}/bins/${id}`;
} catch (err) {
server.logger.fatal("[BIN:CREATE]: Fatal error while deleting files", err);
throw new TRPCError({
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/trpc/v1/dashboard/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const filesRoute = t.router({
})
).query(async (opt) => {
const { query, page, sort } = opt.input;
const { domain, server, req } = opt.ctx;
const { domain, server } = opt.ctx;

let entries = await server.prisma.file.findMany({ where: { domain: domain.domain } });

Expand All @@ -40,7 +40,7 @@ export const filesRoute = t.router({
views: file.views,
visible: file.visible,
ext: Utils.getExtension(file.mimeType || lookup(file.path) || "") || "",
url: `${req.protocol}://${domain}/files/${file.id}`
url: `${Utils.getProtocol()}${domain}/files/${file.id}`
}));

return {
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/trpc/v1/dashboard/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const urlRoute = t.router({
})
).mutation(async (opt) => {
const { url, name, visible } = opt.input;
const { server, domain, req } = opt.ctx;
const { server, domain } = opt.ctx;

const links = await server.prisma.url.findMany({ where: { domain: domain.domain } });
const strategy = domain.nameStrategy === "name" ? "id" : domain.nameStrategy;
Expand All @@ -68,7 +68,7 @@ export const urlRoute = t.router({

try {
await server.prisma.url.create({ data: { date: new Date(), url, id: path, visible, domain: domain.domain } });
return `${req.protocol}://${domain.domain}/r/${path}`;
return `${Utils.getProtocol()}${domain.domain}/r/${path}`;
} catch (err) {
server.logger.fatal("[URL:CREATE]: Fatal error while uploading a shorturl", err);
throw new TRPCError({
Expand Down

0 comments on commit 0d3a72b

Please sign in to comment.