mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
Merge branch 'master' of https://github.com/fosscord/fosscord-api
This commit is contained in:
commit
c041961243
1007
package-lock.json
generated
1007
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,8 @@
|
||||
"start": "npm run build:util && npm run build && node dist/start",
|
||||
"build": "tsc -b .",
|
||||
"build:util": "tsc -b ./node_modules/@fosscord/server-util/",
|
||||
"postinstall": "patch-package"
|
||||
"postinstall": "patch-package",
|
||||
"dev": "tsnd --respawn src/"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -41,7 +42,7 @@
|
||||
"i18next-http-middleware": "^3.1.0",
|
||||
"i18next-node-fs-backend": "^2.1.3",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"lambert-server": "^1.0.10",
|
||||
"lambert-server": "^1.1.9",
|
||||
"missing-native-js-functions": "^1.2.6",
|
||||
"mongodb": "^3.6.4",
|
||||
"mongoose": "^5.12.3",
|
||||
@ -63,6 +64,7 @@
|
||||
"jest": "^26.6.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
"ts-node": "^9.1.1",
|
||||
"ts-node-dev": "^1.1.6",
|
||||
"typescript": "^4.1.2"
|
||||
}
|
||||
}
|
||||
|
@ -25,25 +25,16 @@ router.post(
|
||||
const query: any[] = [{ phone: login }];
|
||||
if (email) query.push({ email });
|
||||
|
||||
const user = await UserModel.findOne(
|
||||
{
|
||||
$or: query,
|
||||
},
|
||||
`user_data.hash id user_settings.locale user_settings.theme`
|
||||
).exec();
|
||||
const user = await UserModel.findOne({ $or: query }, `user_data.hash id user_settings.locale user_settings.theme`).exec();
|
||||
|
||||
if (!user) {
|
||||
throw FieldErrors({
|
||||
login: { message: req.t("auth:login.INVALID_LOGIN"), code: "INVALID_LOGIN" },
|
||||
});
|
||||
throw FieldErrors({ login: { message: req.t("auth:login.INVALID_LOGIN"), code: "INVALID_LOGIN" } });
|
||||
}
|
||||
|
||||
// the salt is saved in the password refer to bcrypt docs
|
||||
const same_password = await bcrypt.compare(password, user.user_data.hash);
|
||||
if (!same_password) {
|
||||
throw FieldErrors({
|
||||
password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" },
|
||||
});
|
||||
throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
|
||||
}
|
||||
|
||||
const token = await generateToken(user.id);
|
||||
|
@ -1,6 +1,35 @@
|
||||
import { ChannelModel, getPermission, MessageDeleteEvent, MessageModel } from "@fosscord/server-util";
|
||||
import { Router } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { emitEvent } from "../../../../../util/Event";
|
||||
import { check } from "../../../../../util/instanceOf";
|
||||
|
||||
const router = Router();
|
||||
// TODO:
|
||||
|
||||
router.delete("/", async (req, res) => {
|
||||
const { message_id, channel_id } = req.params;
|
||||
|
||||
const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true });
|
||||
if (!channel) throw new HTTPError("Channel doesn't exist", 404);
|
||||
|
||||
const permission = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||
permission.hasThrow("MANAGE_MESSAGES");
|
||||
|
||||
await MessageModel.deleteOne({ id: message_id }).exec();
|
||||
|
||||
await emitEvent({
|
||||
event: "MESSAGE_DELETE",
|
||||
channel_id,
|
||||
guild_id: channel.guild_id,
|
||||
data: {
|
||||
id: message_id,
|
||||
channel_id,
|
||||
guild_id: channel.guild_id,
|
||||
},
|
||||
} as MessageDeleteEvent);
|
||||
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@ -27,11 +27,12 @@ router.post("/", check({ messages: [String] }), async (req, res) => {
|
||||
if (messages.length > maxBulkDelete) throw new HTTPError(`You cannot delete more than ${maxBulkDelete} messages`);
|
||||
|
||||
await MessageModel.deleteMany({ id: { $in: messages } }).exec();
|
||||
|
||||
await emitEvent({
|
||||
event: "MESSAGE_DELETE_BULK",
|
||||
channel_id,
|
||||
data: { ids: messages, channel_id, guild_id: channel.guild_id },
|
||||
} as MessageDeleteBulkEvent);
|
||||
|
||||
res.status(204).send();
|
||||
res.sendStatus(204);
|
||||
});
|
||||
|
@ -1,8 +1,4 @@
|
||||
import {
|
||||
Router,
|
||||
Request,
|
||||
Response
|
||||
} from "express";
|
||||
import { Router, Request, Response } from "express";
|
||||
import {
|
||||
ChannelModel,
|
||||
ChannelCreateEvent,
|
||||
@ -10,39 +6,23 @@ import {
|
||||
UserModel,
|
||||
toObject,
|
||||
ChannelType,
|
||||
Snowflake
|
||||
Snowflake,
|
||||
trimSpecial,
|
||||
} from "@fosscord/server-util";
|
||||
import {
|
||||
HTTPError
|
||||
} from "lambert-server";
|
||||
import {
|
||||
emitEvent
|
||||
} from "../../../util/Event";
|
||||
import {
|
||||
getPublicUser
|
||||
} from "../../../util/User";
|
||||
import {
|
||||
DmChannelCreateSchema
|
||||
} from "../../../schema/Channel";
|
||||
import {
|
||||
check
|
||||
} from "../../../util/instanceOf";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { emitEvent } from "../../../util/Event";
|
||||
import { getPublicUser } from "../../../util/User";
|
||||
import { DmChannelCreateSchema } from "../../../schema/Channel";
|
||||
import { check } from "../../../util/instanceOf";
|
||||
|
||||
const router: Router = Router();
|
||||
|
||||
router.get("/", async (req: Request, res: Response) => {
|
||||
const user = await UserModel.findOne({
|
||||
id: req.user_id
|
||||
}, {
|
||||
guilds: true
|
||||
}).exec();
|
||||
if (!user) throw new HTTPError("User not found", 404);
|
||||
|
||||
var testID = "829044530203328513"; //FOR TEST
|
||||
|
||||
var channels = await ChannelModel.find({
|
||||
recipients: req.user_id,
|
||||
type: 1
|
||||
$or: [
|
||||
{ recipients: req.user_id, type: ChannelType.DM },
|
||||
{ recipients: req.user_id, type: ChannelType.GROUP_DM },
|
||||
],
|
||||
}).exec();
|
||||
|
||||
res.json(toObject(channels));
|
||||
@ -50,20 +30,22 @@ router.get("/", async (req: Request, res: Response) => {
|
||||
|
||||
router.post("/", check(DmChannelCreateSchema), async (req, res) => {
|
||||
const body = req.body as DmChannelCreateSchema;
|
||||
if (body.recipients.length === 0) throw new HTTPError("You need to specify at least one recipient");
|
||||
const type = body.recipients.length === 1 ? ChannelType.DM : ChannelType.GROUP_DM;
|
||||
const name = trimSpecial(body.name);
|
||||
|
||||
const channel = {
|
||||
...body,
|
||||
name,
|
||||
type,
|
||||
owner_id: req.user_id,
|
||||
id: Snowflake.generate(),
|
||||
type: ChannelType.DM,
|
||||
created_at: new Date(),
|
||||
};
|
||||
await new ChannelModel(channel).save();
|
||||
|
||||
/*Event({ event: "CHANNEL_CREATE", data: channel } as ChannelCreateEvent);*/
|
||||
|
||||
|
||||
res.json(channel);
|
||||
});
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
@ -49,7 +49,7 @@ router.delete("/:id", async (req: Request, res: Response) => {
|
||||
guild_id: guild_id,
|
||||
} as GuildMemberRemoveEvent);
|
||||
|
||||
return res.status(204).send();
|
||||
return res.sendStatus(204);
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@ -22,21 +22,13 @@ export const ChannelModifySchema = {
|
||||
};
|
||||
|
||||
export const DmChannelCreateSchema = {
|
||||
owner_id: String,
|
||||
$id: String,
|
||||
$created_at: Date,
|
||||
name: String,
|
||||
type: Number,
|
||||
recipients: [String]
|
||||
}
|
||||
$name: String,
|
||||
recipients: [String],
|
||||
};
|
||||
|
||||
export interface DmChannelCreateSchema {
|
||||
owner_id: String;
|
||||
id?: String;
|
||||
created_at?: Date;
|
||||
name: String;
|
||||
type: Number;
|
||||
recipients: String[];
|
||||
name?: string;
|
||||
recipients: string[];
|
||||
}
|
||||
|
||||
export interface ChannelModifySchema {
|
||||
|
Loading…
Reference in New Issue
Block a user