diff --git a/client_test/index.html b/client_test/index.html
index de2fe44b..0da8784a 100644
--- a/client_test/index.html
+++ b/client_test/index.html
@@ -13,12 +13,11 @@
window.GLOBAL_ENV = {
API_ENDPOINT: "/api",
WEBAPP_ENDPOINT: "",
- CDN_HOST: "cdn.discordapp.com",
+ CDN_HOST: "//localhost:3003",
ASSET_ENDPOINT: "",
MEDIA_PROXY_ENDPOINT: "https://media.discordapp.net",
WIDGET_ENDPOINT: "//discord.com/widget",
INVITE_HOST: "discord.gg",
-
GUILD_TEMPLATE_HOST: "discord.new",
GIFT_CODE_HOST: "discord.gift",
RELEASE_CHANNEL: "stable",
diff --git a/src/Server.ts b/src/Server.ts
index 79a8bba3..0ff4df8c 100644
--- a/src/Server.ts
+++ b/src/Server.ts
@@ -97,7 +97,7 @@ export class FosscordServer extends Server {
app.use("/api/v8", prefix);
this.app = app;
this.app.use(ErrorHandler);
- const indexHTML = await fs.readFile(path.join(__dirname, "..", "client_test", "index.html"));
+ const indexHTML = await fs.readFile(path.join(__dirname, "..", "client_test", "index.html"), { encoding: "utf8" });
this.app.use("/assets", express.static(path.join(__dirname, "..", "assets")));
@@ -143,7 +143,12 @@ export class FosscordServer extends Server {
this.app.get("*", (req, res) => {
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
res.set("content-type", "text/html");
- res.send(indexHTML);
+ res.send(
+ indexHTML.replace(
+ /CDN_HOST: ".+"/,
+ `CDN_HOST: "${(Config.get().cdn.endpoint || "http://localhost:3003").replace(/https?:/, "")}"`
+ )
+ );
});
return super.start();
}
diff --git a/src/routes/auth/register.ts b/src/routes/auth/register.ts
index e24485da..50bac43a 100644
--- a/src/routes/auth/register.ts
+++ b/src/routes/auth/register.ts
@@ -181,6 +181,7 @@ router.post(
premium: false,
premium_type: 0,
phone: null,
+ bio: "",
mfa_enabled: false,
verified: false,
disabled: false,
diff --git a/src/routes/users/#id/index.ts b/src/routes/users/#id/index.ts
index 185b2e5f..a2ad3ae6 100644
--- a/src/routes/users/#id/index.ts
+++ b/src/routes/users/#id/index.ts
@@ -6,10 +6,8 @@ const router: Router = Router();
router.get("/", async (req: Request, res: Response) => {
const { id } = req.params;
- const user = await getPublicUser(id);
- if (!user) throw new HTTPError("User not found", 404);
- res.json(user);
+ res.json(await getPublicUser(id));
});
export default router;
diff --git a/src/routes/users/@me/index.ts b/src/routes/users/@me/index.ts
index d139203d..4f17fbee 100644
--- a/src/routes/users/@me/index.ts
+++ b/src/routes/users/@me/index.ts
@@ -2,31 +2,35 @@ import { Router, Request, Response } from "express";
import { UserModel, toObject } from "@fosscord/server-util";
import { HTTPError } from "lambert-server";
import { getPublicUser } from "../../../util/User";
-import { UserModifySchema } from "../../../schema/User"
+import { UserModifySchema } from "../../../schema/User";
import { check } from "../../../util/instanceOf";
+import { uploadFile } from "../../../util/cdn";
const router: Router = Router();
router.get("/", async (req: Request, res: Response) => {
- const user = await UserModel.findOne({ id: req.user_id }).exec();
- if (!user) throw new HTTPError("User not found", 404);
-
- var publicUser = await getPublicUser(user.id);
-
- res.json(publicUser);
+ res.json(await getPublicUser(req.user_id));
});
router.patch("/", check(UserModifySchema), async (req: Request, res: Response) => {
const body = req.body as UserModifySchema;
- const user = await UserModel.findOne({ id: req.user_id }).exec();
- if (!user) throw new HTTPError("User not found", 404);
+ if (body.avatar) {
+ try {
+ const mimetype = body.avatar.split(":")[1].split(";")[0];
+ const buffer = Buffer.from(body.avatar.split(",")[1], "base64");
- var newuser = await UserModel.findOneAndUpdate({ id: req.user_id }, {
- ...body
- }).exec();
+ // @ts-ignore
+ const { id } = await uploadFile(`/avatars/${req.user_id}`, { buffer, mimetype, originalname: "avatar" });
+ body.avatar = id;
+ } catch (error) {
+ throw new HTTPError("Invalid avatar");
+ }
+ }
- res.json(newuser);
+ const user = await UserModel.findOneAndUpdate({ id: req.user_id }, body).exec();
+
+ res.json(toObject(user));
});
export default router;
diff --git a/src/util/instanceOf.ts b/src/util/instanceOf.ts
index b67bde27..93a92805 100644
--- a/src/util/instanceOf.ts
+++ b/src/util/instanceOf.ts
@@ -74,10 +74,9 @@ export function instanceOf(
): Boolean {
if (!ref) ref = { obj: null, key: "" };
if (!path) path = "body";
+ if (!type) return true; // no type was specified
try {
- if (!type) return true; // no type was specified
-
if (value == null) {
if (optional) return true;
throw new FieldError("BASE_TYPE_REQUIRED", req.t("common:field.BASE_TYPE_REQUIRED"));