summary refs log tree commit diff
diff options
context:
space:
mode:
authorNobody <17956512+n0bodysec@users.noreply.github.com>2022-03-08 12:15:38 -0300
committerGitHub <noreply@github.com>2022-03-08 12:15:38 -0300
commitb9be054241786361cfbb678d5b4a1cc580d3eb22 (patch)
tree50abc4b69194837f8087e7d6580e993869cc68bb
parentfix(api): working ban list (diff)
parentTemporary notes fix (diff)
downloadserver-b9be054241786361cfbb678d5b4a1cc580d3eb22.tar.xz
Merge branch 'master' into fix/ban-list
-rw-r--r--Dockerfile45
-rw-r--r--api/assets/openapi.json4
-rw-r--r--api/assets/schemas.json2
-rw-r--r--api/src/routes/guilds/#guild_id/members/#member_id/index.ts6
-rw-r--r--api/src/routes/users/@me/notes.ts6
-rw-r--r--docker-compose.yml48
-rw-r--r--gateway/src/opcodes/Identify.ts2
-rw-r--r--util/src/entities/Member.ts2
-rw-r--r--util/src/entities/User.ts2
-rw-r--r--util/src/interfaces/Status.ts2
10 files changed, 98 insertions, 21 deletions
diff --git a/Dockerfile b/Dockerfile
index d4b423ee..3c8a0b31 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,7 +1,40 @@
-FROM node:14
-WORKDIR /usr/src/fosscord-server/
-COPY . .
-WORKDIR /usr/src/fosscord-server/bundle
+FROM node:alpine
+
+# env vars
+ENV WORK_DIR="/srv/fosscord-server"
+ENV DEV_MODE=0
+ENV HTTP_PORT=3001
+ENV WS_PORT=3002
+ENV CDN_PORT=3003
+ENV RTC_PORT=3004
+ENV ADMIN_PORT=3005
+
+# exposed ports (only for reference, see https://docs.docker.com/engine/reference/builder/#expose)
+EXPOSE ${HTTP_PORT}/tcp ${WS_PORT}/tcp ${CDN_PORT}/tcp ${RTC_PORT}/tcp ${ADMIN_PORT}/tcp
+
+# install required apps
+RUN apk add --no-cache --update git python2 py-pip make build-base
+
+# optionl: packages for debugging/development
+RUN apk add --no-cache sqlite
+
+# download fosscord-server
+WORKDIR $WORK_DIR/src
+RUN git clone https://github.com/fosscord/fosscord-server.git .
+
+# setup and run
+WORKDIR $WORK_DIR/src/bundle
 RUN npm run setup
-EXPOSE 3001
-CMD [ "npm", "run", "start:bundle" ]
+RUN npm install @yukikaze-bot/erlpack
+# RUN npm install mysql --save
+
+# create update script
+RUN printf '#!/bin/sh\n\ngit -C $WORK_DIR/src/ checkout master\ngit -C $WORK_DIR/src/ reset --hard HEAD\ngit -C $WORK_DIR/src/ pull\ncd $WORK_DIR/src/bundle/\nnpm run setup\n' > $WORK_DIR/update.sh
+RUN chmod +x $WORK_DIR/update.sh
+
+# configure entrypoint file
+RUN printf '#!/bin/sh\n\nDEV_MODE=${DEV_MODE:-0}\n\nif [ "$DEV_MODE" -eq 1 ]; then\n    tail -f /dev/null\nelse\n    cd $WORK_DIR/src/bundle/\n    npm run start:bundle\nfi\n' > $WORK_DIR/entrypoint.sh
+RUN chmod +x $WORK_DIR/entrypoint.sh
+
+WORKDIR $WORK_DIR
+ENTRYPOINT ["./entrypoint.sh"]
diff --git a/api/assets/openapi.json b/api/assets/openapi.json
index 1af0600d..03550323 100644
--- a/api/assets/openapi.json
+++ b/api/assets/openapi.json
@@ -3119,7 +3119,7 @@
 						"type": "boolean"
 					},
 					"status": {
-						"enum": ["dnd", "idle", "offline", "online"],
+						"enum": ["dnd", "idle", "offline", "online", "invisible"],
 						"type": "string"
 					},
 					"stream_notifications_enabled": {
@@ -5677,7 +5677,7 @@
 						"type": "boolean"
 					},
 					"status": {
-						"enum": ["dnd", "idle", "offline", "online"],
+						"enum": ["dnd", "idle", "offline", "online", "invisible"],
 						"type": "string"
 					},
 					"stream_notifications_enabled": {
diff --git a/api/assets/schemas.json b/api/assets/schemas.json
index 4ffa44b8..d531df21 100644
--- a/api/assets/schemas.json
+++ b/api/assets/schemas.json
@@ -7897,7 +7897,7 @@
 				"type": "boolean"
 			},
 			"status": {
-				"enum": ["dnd", "idle", "offline", "online"],
+				"enum": ["dnd", "idle", "offline", "online", "invisible"],
 				"type": "string"
 			},
 			"stream_notifications_enabled": {
diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
index 24c74af7..34836292 100644
--- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
@@ -25,13 +25,19 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re
 
 	const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] });
 	const permission = await getPermission(req.user_id, guild_id);
+	const everyone = await Role.findOneOrFail({ guild_id: guild_id, name: "@everyone", position: 0 });
 
 	if (body.roles) {
 		permission.hasThrow("MANAGE_ROLES");
+
+		if (body.roles.indexOf(everyone.id) === -1) body.roles.push(everyone.id);
 		member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist
 	}
 
 	await member.save();
+
+	member.roles = member.roles.filter((x) => x.id !== everyone.id);
+
 	// do not use promise.all as we have to first write to db before emitting the event to catch errors
 	await emitEvent({
 		event: "GUILD_MEMBER_UPDATE",
diff --git a/api/src/routes/users/@me/notes.ts b/api/src/routes/users/@me/notes.ts
index 2ef27bc0..96067bf5 100644
--- a/api/src/routes/users/@me/notes.ts
+++ b/api/src/routes/users/@me/notes.ts
@@ -6,9 +6,9 @@ const router: Router = Router();
 router.put("/:id", route({}), async (req: Request, res: Response) => {
 	//TODO
 	res.json({
-		message: "400: Bad Request",
-		code: 0
-	}).status(400);
+		message: "Unknown User",
+		code: 10013
+	}).status(404);
 });
 
 export default router;
diff --git a/docker-compose.yml b/docker-compose.yml
index 3c03220c..13696f6f 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,7 +1,47 @@
-version: "3"
+version: '3.8'
+
 services:
-  server:
-    image: fosscord/server
+  fosscord:
+    container_name: fosscord
+    image: fosscord
+    restart: on-failure:5
+    # depends_on: mariadb
     build: .
     ports:
-      - 3001:3001
+      - '3001-3005:3001-3005'
+    volumes:
+      # - ./data/:${WORK_DIR:-/srv/fosscord-server}/data/
+      - data:${WORK_DIR:-/srv/fosscord-server}/
+    environment:
+      WORK_DIR: ${WORK_DIR:-/srv/fosscord-server}
+      DEV_MODE: ${DEV_MODE:-0}
+      THREADS: ${THREADS:-1}
+      DATABASE: ${DATABASE:-../../data/database.db}
+      STORAGE_LOCATION: ${STORAGE_LOCATION:-../../data/files/}
+      HTTP_PORT: 3001
+      WS_PORT: 3002
+      CDN_PORT: 3003
+      RTC_PORT: 3004
+      ADMIN_PORT: 3005
+
+  # mariadb:
+  #   image: mariadb:latest
+  #   restart: on-failure:5
+  #   environment:
+  #     MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-secr3tpassw0rd}
+  #     MYSQL_DATABASE: ${MYSQL_DATABASE:-fosscord}
+  #     MYSQL_USER: ${MYSQL_USER:-fosscord}
+  #     MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password1}
+  #   networks:
+  #     - default
+  #   volumes:
+  #     - mariadb:/var/lib/mysql
+
+volumes:
+  data:
+  # mariadb:
+
+networks:
+  default:
+    name: fosscord
+    driver: bridge
diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts
index 904aa963..eb15c28f 100644
--- a/gateway/src/opcodes/Identify.ts
+++ b/gateway/src/opcodes/Identify.ts
@@ -240,8 +240,6 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 			x.guild_hashes = {}; // @ts-ignore
 			x.guild_scheduled_events = []; // @ts-ignore
 			x.threads = [];
-			x.premium_subscription_count = 30;
-			x.premium_tier = 3;
 			return x;
 		}),
 		guild_experiments: [], // TODO
diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts
index 3c5f9db0..b7406881 100644
--- a/util/src/entities/Member.ts
+++ b/util/src/entities/Member.ts
@@ -86,7 +86,7 @@ export class Member extends BaseClassWithoutId {
 	joined_at: Date;
 
 	@Column({ nullable: true })
-	premium_since?: Date;
+	premium_since?: number;
 
 	@Column()
 	deaf: boolean;
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 1d18c838..ed7bd4ce 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -360,7 +360,7 @@ export interface UserSettings {
 	render_reactions: boolean;
 	restricted_guilds: string[];
 	show_current_game: boolean;
-	status: "online" | "offline" | "dnd" | "idle";
+	status: "online" | "offline" | "dnd" | "idle" | "invisible";
 	stream_notifications_enabled: boolean;
 	theme: "dark" | "white"; // dark
 	timezone_offset: number; // e.g -60
diff --git a/util/src/interfaces/Status.ts b/util/src/interfaces/Status.ts
index c4dab586..5d2e1bba 100644
--- a/util/src/interfaces/Status.ts
+++ b/util/src/interfaces/Status.ts
@@ -1,4 +1,4 @@
-export type Status = "idle" | "dnd" | "online" | "offline";
+export type Status = "idle" | "dnd" | "online" | "offline" | "invisible";
 
 export interface ClientStatus {
 	desktop?: string; // e.g. Windows/Linux/Mac