add support for desktop/web
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
1
package-lock.json
generated
@ -45,7 +45,6 @@
|
|||||||
"probe-image-size": "^7.2.3",
|
"probe-image-size": "^7.2.3",
|
||||||
"proxy-agent": "^5.0.0",
|
"proxy-agent": "^5.0.0",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"sqlite3": "*",
|
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typeorm": "^0.3.10",
|
"typeorm": "^0.3.10",
|
||||||
|
@ -22,6 +22,14 @@ import fs from "fs/promises";
|
|||||||
import { HTTPError } from "lambert-server";
|
import { HTTPError } from "lambert-server";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
|
const defaultAvatarHashMap = new Map([
|
||||||
|
["1", "1f0bfc0865d324c2587920a7d80c609b"],
|
||||||
|
["2", "c09a43a372ba81e3018c3151d4ed4773"],
|
||||||
|
["3", "7c8f476123d28d103efe381543274c25"],
|
||||||
|
["4", "6f26ddd1bf59740c536d2274bb834a05"],
|
||||||
|
["5", "3c6ccb83716d1e4fb91d3082f6b21d77"],
|
||||||
|
]);
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
async function getFile(path: string) {
|
async function getFile(path: string) {
|
||||||
@ -41,7 +49,9 @@ async function getFile(path: string) {
|
|||||||
router.get("/avatars/:id", async (req: Request, res: Response) => {
|
router.get("/avatars/:id", async (req: Request, res: Response) => {
|
||||||
let { id } = req.params;
|
let { id } = req.params;
|
||||||
id = id.split(".")[0]; // remove .file extension
|
id = id.split(".")[0]; // remove .file extension
|
||||||
const path = join(process.cwd(), "assets", "default-avatars", `${id}.png`);
|
const hash = defaultAvatarHashMap.get(id);
|
||||||
|
if (!hash) throw new HTTPError("not found", 404);
|
||||||
|
const path = join(process.cwd(), "assets", "public", `${hash}.png`);
|
||||||
|
|
||||||
const file = await getFile(path);
|
const file = await getFile(path);
|
||||||
if (!file) throw new HTTPError("not found", 404);
|
if (!file) throw new HTTPError("not found", 404);
|
||||||
|