1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-06 10:52:31 +01:00

Partial integration of categories and discovery

This commit is contained in:
Featyre 2022-01-23 23:55:43 +08:00
parent 12edecb723
commit a5e06cd021
10 changed files with 96 additions and 46 deletions

View File

@ -0,0 +1,27 @@
import { Router, Response, Request } from "express";
import { route } from "@fosscord/api";
const router = Router();
router.get("/", route({}), (req: Request, res: Response) => {
// TODO:
// Load categories from db instead
const { locale, primary_only } = req.query;
let out;
switch (locale) {
case "en-US":
switch (primary_only) {
case "false":
out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 15, "is_primary": false, "name": "Esports"}, {"id": 30, "is_primary": false, "name": "LFG"}, {"id": 32, "is_primary": false, "name": "Theorycraft"}, {"id": 36, "is_primary": false, "name": "Business"}, {"id": 39, "is_primary": false, "name": "Fandom"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 18, "is_primary": false, "name": "Books"}, {"id": 23, "is_primary": false, "name": "Podcasts"}, {"id": 28, "is_primary": false, "name": "Investing"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 45, "is_primary": false, "name": "Mobile"}, {"id": 16, "is_primary": false, "name": "Anime & Manga"}, {"id": 17, "is_primary": false, "name": "Movies & TV"}, {"id": 19, "is_primary": false, "name": "Art"}, {"id": 20, "is_primary": false, "name": "Writing"}, {"id": 22, "is_primary": false, "name": "Programming"}, {"id": 25, "is_primary": false, "name": "Memes"}, {"id": 27, "is_primary": false, "name": "Cryptocurrency"}, {"id": 31, "is_primary": false, "name": "Customer Support"}, {"id": 33, "is_primary": false, "name": "Events"}, {"id": 34, "is_primary": false, "name": "Roleplay"}, {"id": 37, "is_primary": false, "name": "Local Group"}, {"id": 38, "is_primary": false, "name": "Collaboration"}, {"id": 40, "is_primary": false, "name": "Wiki & Guide"}, {"id": 42, "is_primary": false, "name": "Subreddit"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}, {"id": 21, "is_primary": false, "name": "Crafts, DIY, & Making"}, {"id": 48, "is_primary": false, "name": "Game Developer"}, {"id": 49, "is_primary": true, "name": "Bots"}, {"id": 24, "is_primary": false, "name": "Tabletop Games"}, {"id": 26, "is_primary": false, "name": "News & Current Events"}, {"id": 29, "is_primary": false, "name": "Studying & Teaching"}, {"id": 35, "is_primary": false, "name": "Content Creator"}, {"id": 44, "is_primary": false, "name": "Comics & Cartoons"}, {"id": 46, "is_primary": false, "name": "Console"}, {"id": 47, "is_primary": false, "name": "Charity & Nonprofit"}]
case "true":
out = [{"id": 0, "is_primary": true, "name": "General"}, {"id": 10, "is_primary": true, "name": "Travel & Food"}, {"id": 43, "is_primary": true, "name": "Emoji"}, {"id": 7, "is_primary": true, "name": "Sports"}, {"id": 13, "is_primary": true, "name": "Other"}, {"id": 2, "is_primary": true, "name": "Music"}, {"id": 3, "is_primary": true, "name": "Entertainment"}, {"id": 4, "is_primary": true, "name": "Creative Arts"}, {"id": 6, "is_primary": true, "name": "Education"}, {"id": 9, "is_primary": true, "name": "Relationships & Identity"}, {"id": 11, "is_primary": true, "name": "Fitness & Health"}, {"id": 12, "is_primary": true, "name": "Finance"}, {"id": 1, "is_primary": true, "name": "Gaming"}, {"id": 5, "is_primary": true, "name": "Science & Tech"}, {"id": 8, "is_primary": true, "name": "Fashion & Beauty"}, {"id": 14, "is_primary": true, "name": "General Chatting"}]
}
}
res.json(out).status(200);
});
export default router;

View File

@ -6,15 +6,26 @@ import { route } from "@fosscord/api";
const router = Router(); const router = Router();
router.get("/", route({}), async (req: Request, res: Response) => { router.get("/", route({}), async (req: Request, res: Response) => {
const { limit } = req.params; const { limit, categories } = req.query;
var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery; var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery;
// ! this only works using SQL querys // ! this only works using SQL querys
// TODO: implement this with default typeorm query // TODO: implement this with default typeorm query
// const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) }); // const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) });
const guilds = showAllGuilds let guilds;
? await Guild.find({ take: Math.abs(Number(limit || 20)) }) let total;
: await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 20)) }); switch (categories) {
res.send({ guilds: guilds }); case "1":
guilds = showAllGuilds
? await Guild.find({ take: Math.abs(Number(limit || 24)) })
: await Guild.find({ where: `"primary_category_id" = 1 AND "features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) });
total = guilds.length;
default:
guilds = showAllGuilds
? await Guild.find({ take: Math.abs(Number(limit || 24)) })
: await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) });
total = guilds.length;
}
res.send({ total: total, guilds: guilds, offset: 0, limit: limit});
}); });
export default router; export default router;

View File

@ -1,12 +0,0 @@
import { Router, Response, Request } from "express";
import { route } from "@fosscord/api";
const router = Router();
router.get("/categories", route({}), (req: Request, res: Response) => {
// TODO:
//const { locale, primary_only } = req.query;
res.json([]).status(200);
});
export default router;

View File

@ -6,14 +6,14 @@ import { route } from "@fosscord/api";
const router = Router(); const router = Router();
router.get("/", route({}), async (req: Request, res: Response) => { router.get("/", route({}), async (req: Request, res: Response) => {
const { limit, personalization_disabled } = req.params; const { limit, personalization_disabled } = req.query;
var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery; var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery;
// ! this only works using SQL querys // ! this only works using SQL querys
// TODO: implement this with default typeorm query // TODO: implement this with default typeorm query
// const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) }); // const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) });
const guilds = showAllGuilds const guilds = showAllGuilds
? await Guild.find({ take: Math.abs(Number(limit || 20)) }) ? await Guild.find({ take: Math.abs(Number(limit || 24)) })
: await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 100)) }); : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) });
res.send({ recommended_guilds: guilds }); res.send({ recommended_guilds: guilds });
}); });

View File

@ -95,9 +95,10 @@
} }
}, },
"../api": { "../api": {
"name": "@fosscord/api",
"version": "1.0.0", "version": "1.0.0",
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "GPLV3",
"dependencies": { "dependencies": {
"@babel/preset-env": "^7.15.8", "@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0", "@babel/preset-typescript": "^7.15.0",
@ -158,8 +159,9 @@
} }
}, },
"../cdn": { "../cdn": {
"name": "@fosscord/cdn",
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "GPLV3",
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.36.1", "@aws-sdk/client-s3": "^3.36.1",
"@aws-sdk/node-http-handler": "^3.36.0", "@aws-sdk/node-http-handler": "^3.36.0",
@ -200,9 +202,10 @@
} }
}, },
"../gateway": { "../gateway": {
"name": "@fosscord/gateway",
"version": "1.0.0", "version": "1.0.0",
"hasInstallScript": true, "hasInstallScript": true,
"license": "ISC", "license": "GPLV3",
"dependencies": { "dependencies": {
"@fosscord/util": "file:../util", "@fosscord/util": "file:../util",
"amqplib": "^0.8.0", "amqplib": "^0.8.0",

View File

@ -107,4 +107,4 @@
"ws": "^7.4.2", "ws": "^7.4.2",
"nanocolors": "^0.2.12" "nanocolors": "^0.2.12"
} }
} }

View File

@ -0,0 +1,36 @@
import { PrimaryColumn, Column, Entity} from "typeorm";
import { BaseClassWithoutId } from "./BaseClass";
// TODO: categories:
// [{
// "id": 16,
// "default": "Anime & Manga",
// "localizations": {
// "de": "Anime & Manga",
// "fr": "Anim\u00e9s et mangas",
// "ru": "\u0410\u043d\u0438\u043c\u0435 \u0438 \u043c\u0430\u043d\u0433\u0430"
// }
// },
// "is_primary": false/true
// }]
@Entity("categories")
export class Categories extends BaseClassWithoutId { // Not using snowflake
@PrimaryColumn()
id: number;
@Column()
default: string;
@Column({ type: "simple-json", nullable: false })
localizations: string;
@Column()
is_primary: boolean;
}
export interface DefaultCategoryValue { // TODO: Load Default Discord Categories
}

View File

@ -158,6 +158,7 @@ export interface ConfigValue {
}; };
guild: { guild: {
showAllGuildsInDiscovery: boolean; showAllGuildsInDiscovery: boolean;
homeDiscoveryUseRecommendation: boolean; // TODO: Recommendation, privacy concern?
autoJoin: { autoJoin: {
enabled: boolean; enabled: boolean;
guilds: string[]; guilds: string[];
@ -354,6 +355,7 @@ export const DefaultConfigOptions: ConfigValue = {
}, },
guild: { guild: {
showAllGuildsInDiscovery: false, showAllGuildsInDiscovery: false,
homeDiscoveryUseRecommendation: false,
autoJoin: { autoJoin: {
enabled: true, enabled: true,
canLeave: true, canLeave: true,

View File

@ -17,28 +17,6 @@ import { Webhook } from "./Webhook";
// TODO: guild_scheduled_events // TODO: guild_scheduled_events
// TODO: stage_instances // TODO: stage_instances
// TODO: threads // TODO: threads
// TODO: categories:
// [{
// "id": 16,
// "name": {
// "default": "Anime & Manga",
// "localizations": {
// "de": "Anime & Manga",
// "fr": "Anim\u00e9s et mangas",
// "ru": "\u0410\u043d\u0438\u043c\u0435 \u0438 \u043c\u0430\u043d\u0433\u0430"
// }
// },
// "is_primary": false
// }]
// TODO:
// primary_category :{
// id: 1,
// name: {
// default: "Gaming",
// localizations: { de: "Gaming", fr: "Gaming", ru: "\u0418\u0433\u0440\u044b" },
// is_primary: true,
// },
// };
// TODO: // TODO:
// "keywords": [ // "keywords": [
// "Genshin Impact", // "Genshin Impact",
@ -107,6 +85,9 @@ export class Guild extends BaseClass {
features: string[]; //TODO use enum features: string[]; //TODO use enum
//TODO: https://discord.com/developers/docs/resources/guild#guild-object-guild-features //TODO: https://discord.com/developers/docs/resources/guild#guild-object-guild-features
@Column({ nullable: true })
primary_category_id: number;
@Column({ nullable: true }) @Column({ nullable: true })
icon?: string; icon?: string;
@ -306,6 +287,7 @@ export class Guild extends BaseClass {
default_message_notifications: 1, // defaults effect: setting the push default at mentions-only will save a lot default_message_notifications: 1, // defaults effect: setting the push default at mentions-only will save a lot
explicit_content_filter: 0, explicit_content_filter: 0,
features: [], features: [],
primary_category_id: 0,
id: guild_id, id: guild_id,
max_members: 250000, max_members: 250000,
max_presences: 250000, max_presences: 250000,

View File

@ -3,6 +3,7 @@ export * from "./Attachment";
export * from "./AuditLog"; export * from "./AuditLog";
export * from "./Ban"; export * from "./Ban";
export * from "./BaseClass"; export * from "./BaseClass";
export * from "./Categories";
export * from "./Channel"; export * from "./Channel";
export * from "./Config"; export * from "./Config";
export * from "./ConnectedAccount"; export * from "./ConnectedAccount";