mirror of
https://github.com/PreMiD/PreMiD.git
synced 2026-04-06 04:41:58 +02:00
feat: add session-keep-alive
This commit is contained in:
@@ -1,36 +1,38 @@
|
||||
import { REST } from "@discordjs/rest";
|
||||
import { mainLog, redis } from "../index.js";
|
||||
|
||||
export async function clearOldSesssions() {
|
||||
const sessions = await redis.hgetall("pmd-api.sessions");
|
||||
const now = Date.now();
|
||||
export async function clearOldSessions() {
|
||||
const sessionKeys = await redis.keys("pmd:session:*");
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
|
||||
if (Object.keys(sessions).length === 0) {
|
||||
if (sessionKeys.length === 0) {
|
||||
mainLog("No sessions to clear");
|
||||
return;
|
||||
}
|
||||
|
||||
mainLog(`Checking ${Object.keys(sessions).length} sessions`);
|
||||
mainLog(`Checking ${sessionKeys.length} sessions`);
|
||||
|
||||
let cleared = 0;
|
||||
for (const [key, value] of Object.entries(sessions)) {
|
||||
const session = JSON.parse(value) as {
|
||||
token: string;
|
||||
session: string;
|
||||
lastUpdated: number;
|
||||
};
|
||||
for (const key of sessionKeys) {
|
||||
const session = await redis.hgetall(key);
|
||||
|
||||
// ? If the session is younger than 30seconds, skip it
|
||||
if (now - session.lastUpdated < 30000)
|
||||
if (!session.t || !session.u) {
|
||||
await redis.del(key);
|
||||
cleared++;
|
||||
continue;
|
||||
}
|
||||
|
||||
//* If the session is younger than 30 seconds, skip it
|
||||
if (now - Number(session.u) < 30)
|
||||
continue;
|
||||
|
||||
// ? Delete the session
|
||||
//* Delete the session
|
||||
try {
|
||||
const discord = new REST({ version: "10", authPrefix: "Bearer" });
|
||||
discord.setToken(session.token);
|
||||
discord.setToken(session.t);
|
||||
await discord.post("/users/@me/headless-sessions/delete", {
|
||||
body: {
|
||||
token: session.session,
|
||||
token: key.split(":")[2], // Extract session token from key
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -39,8 +41,7 @@ export async function clearOldSesssions() {
|
||||
}
|
||||
|
||||
cleared++;
|
||||
|
||||
await redis.hdel("pmd-api.sessions", key);
|
||||
await redis.del(key);
|
||||
}
|
||||
|
||||
mainLog(`Cleared ${cleared} sessions`);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { CronJob } from "cron";
|
||||
|
||||
import debug from "debug";
|
||||
import { clearOldSessions } from "./functions/clearOldSessions.js";
|
||||
import createRedis from "./functions/createRedis.js";
|
||||
import { clearOldSesssions } from "./functions/clearOldSessions.js";
|
||||
|
||||
export const redis = createRedis();
|
||||
|
||||
@@ -14,7 +14,7 @@ void new CronJob(
|
||||
// Every 5 seconds
|
||||
"*/5 * * * * *",
|
||||
async () => {
|
||||
clearOldSesssions();
|
||||
clearOldSessions();
|
||||
},
|
||||
undefined,
|
||||
true,
|
||||
|
||||
1
apps/api-worker/environment.d.ts
vendored
1
apps/api-worker/environment.d.ts
vendored
@@ -2,5 +2,6 @@ declare namespace NodeJS {
|
||||
export interface ProcessEnv {
|
||||
NODE_ENV?: "development" | "production" | "test";
|
||||
DATABASE_URL?: string;
|
||||
SESSION_KEEP_ALIVE_INTERVAL?: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { scope, type } from "arktype";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
import WebSocket from "ws";
|
||||
import type { RawData } from "ws";
|
||||
import { REST } from "@discordjs/rest";
|
||||
import { scope, type } from "arktype";
|
||||
import { Routes } from "discord-api-types/v10";
|
||||
import WebSocket from "ws";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
import type { RawData } from "ws";
|
||||
import { redis } from "../functions/createServer.js";
|
||||
import { counter } from "../tracing.js";
|
||||
|
||||
@@ -11,20 +11,20 @@ const schema = scope({
|
||||
token: {
|
||||
"+": "delete",
|
||||
"type": "'token'",
|
||||
"token": "format.trim",
|
||||
"expires": "unixTimestamp",
|
||||
"token": "string.trim",
|
||||
"expires": "number.epoch",
|
||||
},
|
||||
session: {
|
||||
"+": "delete",
|
||||
"type": "'session'",
|
||||
"token": "format.trim",
|
||||
"token": "string.trim",
|
||||
},
|
||||
validMessages: "token | session",
|
||||
}).export();
|
||||
|
||||
export class Socket {
|
||||
currentToken: typeof schema.token.infer | undefined;
|
||||
currentSesssion: typeof schema.session.infer | undefined;
|
||||
currentSession: typeof schema.session.infer | undefined;
|
||||
discord = new REST({ version: "10", authPrefix: "Bearer" });
|
||||
|
||||
constructor(
|
||||
@@ -54,8 +54,8 @@ export class Socket {
|
||||
break;
|
||||
}
|
||||
case "session": {
|
||||
await redis.hdel("pmd-api.sessions", out.token);
|
||||
this.currentSesssion = out;
|
||||
await redis.del(`pmd:session:${out.token}`);
|
||||
this.currentSession = out;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -69,18 +69,20 @@ export class Socket {
|
||||
async onClose() {
|
||||
counter.add(-1);
|
||||
|
||||
if (!this.currentToken || !this.currentSesssion)
|
||||
if (!this.currentToken || !this.currentSession)
|
||||
return;
|
||||
|
||||
await redis.hset(
|
||||
"pmd-api.sessions",
|
||||
this.currentSesssion.token,
|
||||
JSON.stringify({
|
||||
session: this.currentSesssion.token,
|
||||
token: this.currentToken.token,
|
||||
lastUpdated: Date.now(),
|
||||
}),
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
|
||||
await redis.hmset(
|
||||
`pmd:session:${this.currentSession.token}`,
|
||||
{
|
||||
t: this.currentToken.token,
|
||||
u: now,
|
||||
},
|
||||
);
|
||||
|
||||
await redis.expire(`pmd:session:${this.currentSession.token}`, 60); // Expire after 1 minute
|
||||
}
|
||||
|
||||
async isTokenValid(token: typeof schema.token.infer) {
|
||||
|
||||
@@ -6,14 +6,15 @@ import { maxAliasesPlugin } from "@escape.tech/graphql-armor-max-aliases";
|
||||
import { maxDepthPlugin } from "@escape.tech/graphql-armor-max-depth";
|
||||
import { maxDirectivesPlugin } from "@escape.tech/graphql-armor-max-directives";
|
||||
import { maxTokensPlugin } from "@escape.tech/graphql-armor-max-tokens";
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import fastify from "fastify";
|
||||
import { createSchema, createYoga } from "graphql-yoga";
|
||||
|
||||
import fastifyWebsocket from "@fastify/websocket";
|
||||
import { defu } from "defu";
|
||||
import { resolvers } from "../graphql/resolvers/v5/index.js";
|
||||
import fastify from "fastify";
|
||||
|
||||
import { createSchema, createYoga } from "graphql-yoga";
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { Socket } from "../classes/Socket.js";
|
||||
import { resolvers } from "../graphql/resolvers/v5/index.js";
|
||||
import { sessionKeepAlive } from "../routes/sessionKeepAlive.js";
|
||||
import createRedis from "./createRedis.js";
|
||||
|
||||
export interface FastifyContext {
|
||||
@@ -91,11 +92,14 @@ export default async function createServer() {
|
||||
|
||||
const test = defu(flags, {
|
||||
WebSocketManager: true,
|
||||
SessionKeepAlive: true,
|
||||
});
|
||||
|
||||
void reply.send(test);
|
||||
});
|
||||
|
||||
app.post("/v5/session-keep-alive", sessionKeepAlive);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type } from "arktype";
|
||||
import type { MutationResolvers } from "../../../../generated/graphql-v5.js";
|
||||
import { redis } from "../../../../functions/createServer.js";
|
||||
import type { MutationResolvers } from "../../../../generated/graphql-v5.js";
|
||||
|
||||
const addScienceSchema = type({
|
||||
identifier: "uuid & format.lowercase",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { MutationResolvers } from "../../../../generated/graphql-v5.js";
|
||||
import addScience from "./addScience.js";
|
||||
import heartbeat from "./heartbeat.js";
|
||||
import type { MutationResolvers } from "../../../../generated/graphql-v5.js";
|
||||
|
||||
export const Mutation: MutationResolvers = {
|
||||
addScience,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { QueryResolvers } from "../../../../generated/graphql-v5.js";
|
||||
import presences from "./presences.js";
|
||||
import type { QueryResolvers } from "../../../../generated/graphql-v5.js";
|
||||
|
||||
export const Query: QueryResolvers = {
|
||||
presences,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Presence } from "@premid/db";
|
||||
import type { PresenceSchema } from "@premid/db/Presence.js";
|
||||
import { parseResolveInfo } from "graphql-parse-resolve-info";
|
||||
import type { PresenceSchema } from "@premid/db/Presence.js";
|
||||
import type { FilterQuery } from "mongoose";
|
||||
|
||||
import type { QueryResolvers } from "../../../../generated/graphql-v5.js";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Resolvers } from "../../../generated/graphql-v5.js";
|
||||
import { Query } from "./Query/index.js";
|
||||
import { Mutation } from "./Mutation/index.js";
|
||||
import { Query } from "./Query/index.js";
|
||||
import type { Resolvers } from "../../../generated/graphql-v5.js";
|
||||
|
||||
export const resolvers: Resolvers = {
|
||||
Query,
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
type Mutation {
|
||||
addScience(
|
||||
identifier: String!
|
||||
presences: [String!]!
|
||||
platform: PlatformInput!
|
||||
): AddScienceResult
|
||||
addScience(identifier: String!, presences: [String!]!, platform: PlatformInput!): AddScienceResult
|
||||
}
|
||||
|
||||
input PlatformInput {
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as Sentry from "@sentry/node";
|
||||
import { connect } from "mongoose";
|
||||
import "./tracing.js";
|
||||
|
||||
// eslint-disable-next-line perfectionist/sort-imports
|
||||
import createServer from "./functions/createServer.js";
|
||||
|
||||
// TODO SETUP SENTRY
|
||||
|
||||
59
apps/api-worker/src/routes/sessionKeepAlive.ts
Normal file
59
apps/api-worker/src/routes/sessionKeepAlive.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import process from "node:process";
|
||||
import { REST } from "@discordjs/rest";
|
||||
import { type } from "arktype";
|
||||
import { Routes } from "discord-api-types/v10";
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { redis } from "../functions/createServer.js";
|
||||
|
||||
const schema = type({
|
||||
token: "string.trim",
|
||||
session: "string.trim",
|
||||
});
|
||||
|
||||
export async function sessionKeepAlive(request: FastifyRequest, reply: FastifyReply) {
|
||||
//* Get the 2 headers
|
||||
const out = schema({
|
||||
token: request.headers["x-token"],
|
||||
session: request.headers["x-session"],
|
||||
});
|
||||
|
||||
if (out instanceof type.errors)
|
||||
return reply.status(400).send({ code: "MISSING_HEADERS", message: out.message });
|
||||
|
||||
if (!await isTokenValid(out.token))
|
||||
return reply.status(400).send({ code: "INVALID_TOKEN", message: "The token is invalid" });
|
||||
|
||||
const now = Math.floor(Date.now() / 1000); // Unix timestamp in seconds
|
||||
|
||||
await redis.hmset(
|
||||
`pmd:session:${out.session}`,
|
||||
{
|
||||
t: out.token,
|
||||
u: now,
|
||||
},
|
||||
);
|
||||
|
||||
// Set expiration for the hash
|
||||
await redis.expire(`pmd:session:${out.session}`, 60); // Expire after 1 minute
|
||||
|
||||
const interval = Number.parseInt(process.env.SESSION_KEEP_ALIVE_INTERVAL ?? "5000");
|
||||
|
||||
return reply.status(200).send({
|
||||
code: "OK",
|
||||
message: "Session updated",
|
||||
nextUpdate: interval,
|
||||
});
|
||||
}
|
||||
|
||||
async function isTokenValid(token: string) {
|
||||
const discord = new REST({ version: "10", authPrefix: "Bearer" });
|
||||
|
||||
discord.setToken(token);
|
||||
try {
|
||||
await discord.get(Routes.user());
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ValueType } from "@opentelemetry/api";
|
||||
import { PrometheusExporter } from "@opentelemetry/exporter-prometheus";
|
||||
import { MeterProvider } from "@opentelemetry/sdk-metrics";
|
||||
import { ValueType } from "@opentelemetry/api";
|
||||
|
||||
const prometheusExporter = new PrometheusExporter();
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import crypto from "node:crypto";
|
||||
|
||||
import process from "node:process";
|
||||
import type { RouteHandlerMethod } from "fastify";
|
||||
import mime from "mime-types";
|
||||
import { nanoid } from "nanoid";
|
||||
import type { RouteHandlerMethod } from "fastify";
|
||||
|
||||
import keyv from "../keyv.js";
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Buffer } from "node:buffer";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { afterAll, beforeAll, describe, it } from "vitest";
|
||||
|
||||
import type { RequestOptions } from "node:http";
|
||||
import type { AddressInfo } from "node:net";
|
||||
|
||||
import { Buffer } from "node:buffer";
|
||||
import { afterAll, beforeAll, describe, it } from "vitest";
|
||||
|
||||
import { createServer } from "../functions/createServer.js";
|
||||
|
||||
describe.concurrent("createFromImage", async () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import crypto from "node:crypto";
|
||||
|
||||
import process from "node:process";
|
||||
import type { RouteHandlerMethod } from "fastify";
|
||||
import { fileTypeFromBuffer } from "file-type";
|
||||
import { nanoid } from "nanoid";
|
||||
import type { RouteHandlerMethod } from "fastify";
|
||||
|
||||
import keyv from "../keyv.js";
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import crypto from "node:crypto";
|
||||
|
||||
import process from "node:process";
|
||||
import type { RouteHandlerMethod } from "fastify";
|
||||
import { nanoid } from "nanoid";
|
||||
import type { RouteHandlerMethod } from "fastify";
|
||||
|
||||
import keyv from "../keyv.js";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { Buffer } from "node:buffer";
|
||||
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createServer } from "../functions/createServer.js";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import crypto from "node:crypto";
|
||||
|
||||
import { Buffer } from "node:buffer";
|
||||
|
||||
import crypto from "node:crypto";
|
||||
import type { RouteHandlerMethod } from "fastify";
|
||||
|
||||
import isInCIDRRange from "../functions/isInCidRange.js";
|
||||
|
||||
@@ -2,9 +2,9 @@ import { extname, resolve } from "node:path";
|
||||
|
||||
import process from "node:process";
|
||||
import helmet from "@fastify/helmet";
|
||||
import type { RequestGenericInterface } from "fastify";
|
||||
import fastify from "fastify";
|
||||
import { globby } from "globby";
|
||||
import type { RequestGenericInterface } from "fastify";
|
||||
|
||||
export const app = fastify();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { LocationQuery } from "vue-router";
|
||||
import { useExtensionStore } from "~/stores/useExtension";
|
||||
import breakpoints from "~/breakpoints";
|
||||
import { useExtensionStore } from "~/stores/useExtension";
|
||||
|
||||
const extension = useExtensionStore();
|
||||
|
||||
@@ -19,17 +19,23 @@ const selectedCategory = ref("");
|
||||
|
||||
const sortBy = ref<string>("");
|
||||
const pageSize = ref(9);
|
||||
const totalPages = computed(() => Math.ceil(data.value.presences.length / pageSize.value));
|
||||
const totalPages = computed(() =>
|
||||
Math.ceil(data.value.presences.length / pageSize.value),
|
||||
);
|
||||
|
||||
const presences = computed(() => {
|
||||
const startIndex = (currentPage.value - 1) * pageSize.value;
|
||||
const endIndex = startIndex + pageSize.value;
|
||||
const sortedPresences = (
|
||||
selectedCategory.value
|
||||
? data.value.presences.filter(p => p.metadata.category === selectedCategory.value)
|
||||
? data.value.presences.filter(
|
||||
p => p.metadata.category === selectedCategory.value,
|
||||
)
|
||||
: data.value.presences
|
||||
)
|
||||
.filter(p => p.metadata.service.toLowerCase().includes(searchTerm.value.toLowerCase()))
|
||||
.filter(p =>
|
||||
p.metadata.service.toLowerCase().includes(searchTerm.value.toLowerCase()),
|
||||
)
|
||||
.sort((a, b) => {
|
||||
if (sortBy.value === t("component.searchBar.sort.mostUsed"))
|
||||
return b.users - a.users;
|
||||
@@ -37,7 +43,7 @@ const presences = computed(() => {
|
||||
return a.metadata.service.localeCompare(b.metadata.service);
|
||||
return 0;
|
||||
})
|
||||
.sort(a => extension.presences.includes(a.metadata.service) ? -1 : 1);
|
||||
.sort(a => (extension.presences.includes(a.metadata.service) ? -1 : 1));
|
||||
|
||||
return {
|
||||
data: sortedPresences.slice(startIndex, endIndex),
|
||||
@@ -48,7 +54,9 @@ const presences = computed(() => {
|
||||
|
||||
async function handleQuery(query: LocationQuery) {
|
||||
const pageQuery = query.page?.toString() || "1";
|
||||
const parsedPage = Number.parseInt(Number.isNaN(Number(pageQuery)) ? "1" : pageQuery);
|
||||
const parsedPage = Number.parseInt(
|
||||
Number.isNaN(Number(pageQuery)) ? "1" : pageQuery,
|
||||
);
|
||||
currentPage.value = Math.max(1, Math.min(parsedPage, totalPages.value));
|
||||
searchTerm.value = query.search?.toString() || "";
|
||||
selectedCategory.value = query.category?.toString() || "";
|
||||
@@ -71,10 +79,16 @@ onUnmounted(() => {
|
||||
window.removeEventListener("resize", resizePageSize);
|
||||
});
|
||||
|
||||
function getLinkProperties({ page = currentPage.value, search = searchTerm.value, category = selectedCategory.value }) {
|
||||
function getLinkProperties({
|
||||
page = currentPage.value,
|
||||
search = searchTerm.value,
|
||||
category = selectedCategory.value,
|
||||
}) {
|
||||
const query = { category, page, search };
|
||||
return {
|
||||
query: Object.fromEntries(Object.entries(query).filter(([, value]) => value !== "")),
|
||||
query: Object.fromEntries(
|
||||
Object.entries(query).filter(([, value]) => value !== ""),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,18 +115,35 @@ onMounted(() => {
|
||||
<div>
|
||||
<StoreSearchBar v-model:sort-order="sortBy" />
|
||||
<!-- Presences Grid or Empty State -->
|
||||
<div v-if="presences.data.length === 0" class="flex justify-center items-center rounded-lg h-50">
|
||||
<div class="flex flex-col items-center justify-center p-5 text-lg text-primary-highlight">
|
||||
<div
|
||||
v-if="presences.data.length === 0"
|
||||
class="flex justify-center items-center rounded-lg h-50"
|
||||
>
|
||||
<div
|
||||
class="flex flex-col items-center justify-center p-5 text-lg text-primary-highlight"
|
||||
>
|
||||
<FAIcon :icon="['fa', 'frown']" class="mb-2 text-3xl" />
|
||||
<p>{{ $t("page.store.noPresence") }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="presences.data.length > 0" class="items-center mt-5 flex-col flex sm:mt-10 min-h-688px">
|
||||
<div class="gap-4 grid grid-cols-[fit-content(0%)] sm-md:grid-cols-[repeat(2,fit-content(0%))] lg:grid-cols-[repeat(3,fit-content(0%))] overflow-unset">
|
||||
<StoreCard v-for="presence in presences.data" :key="presence.metadata.service" :presence="presence" />
|
||||
<div
|
||||
v-if="presences.data.length > 0"
|
||||
class="items-center mt-5 flex-col flex sm:mt-10 min-h-688px"
|
||||
>
|
||||
<div
|
||||
class="gap-4 grid grid-cols-[fit-content(0%)] sm-md:grid-cols-[repeat(2,fit-content(0%))] lg:grid-cols-[repeat(3,fit-content(0%))] overflow-unset"
|
||||
>
|
||||
<StoreCard
|
||||
v-for="presence in presences.data"
|
||||
:key="presence.metadata.service"
|
||||
:presence="presence"
|
||||
/>
|
||||
</div>
|
||||
<!-- Pagination -->
|
||||
<div v-if="presences.data.length > 0" class="flex mt-5 mb-10 flex-wrap justify-center sticky z-40">
|
||||
<div
|
||||
v-if="presences.data.length > 0"
|
||||
class="flex mt-5 mb-10 flex-wrap justify-center sticky z-40"
|
||||
>
|
||||
<NuxtLink
|
||||
:to="getLinkProperties({ page: 1 })"
|
||||
:replace="true"
|
||||
@@ -148,7 +179,7 @@ onMounted(() => {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
#filters {
|
||||
#filters {
|
||||
&::-webkit-scrollbar {
|
||||
width: 0.4rem;
|
||||
height: 100%;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { library } from "@fortawesome/fontawesome-svg-core";
|
||||
import { faBrave, faChrome, faDiscord, faEdge, faFirefox, faGithub, faOpera, faPatreon, faSafari, faXTwitter } from "@fortawesome/free-brands-svg-icons";
|
||||
import {
|
||||
faBars,
|
||||
faBolt,
|
||||
@@ -33,7 +34,6 @@ import {
|
||||
faUsers,
|
||||
faVideo,
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
import { faBrave, faChrome, faDiscord, faEdge, faFirefox, faGithub, faOpera, faPatreon, faSafari, faXTwitter } from "@fortawesome/free-brands-svg-icons";
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
library.add(
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ActivityType, flagsToBadges, PresenceUpdateStatus } from "@discord-user-card/vue";
|
||||
import { REST } from "@discordjs/rest";
|
||||
import type { RESTGetAPIGuildMemberResult, RESTGetAPIGuildRolesResult } from "discord-api-types/v10";
|
||||
import { Routes } from "discord-api-types/v10";
|
||||
import type { DiscordUserCardActivity, DiscordUserCardUser } from "@discord-user-card/vue";
|
||||
import { ActivityType, PresenceUpdateStatus, flagsToBadges } from "@discord-user-card/vue";
|
||||
import type { RESTGetAPIGuildMemberResult, RESTGetAPIGuildRolesResult } from "discord-api-types/v10";
|
||||
|
||||
const { discord_bot_token } = useRuntimeConfig();
|
||||
const rest = new REST({ version: "10" }).setToken(discord_bot_token);
|
||||
@@ -61,7 +61,8 @@ const activities: Map<string, DiscordUserCardActivity[]> = new Map()
|
||||
},
|
||||
],
|
||||
} satisfies DiscordUserCardActivity,
|
||||
]).set("193714715631812608", [
|
||||
])
|
||||
.set("193714715631812608", [
|
||||
{
|
||||
type: ActivityType.Playing,
|
||||
name: "Kotobade Asobou",
|
||||
@@ -73,7 +74,8 @@ const activities: Map<string, DiscordUserCardActivity[]> = new Map()
|
||||
],
|
||||
startTimestamp: Date.now(),
|
||||
} satisfies DiscordUserCardActivity,
|
||||
]).set("205984221859151873", [
|
||||
])
|
||||
.set("205984221859151873", [
|
||||
{
|
||||
type: ActivityType.Playing,
|
||||
name: "BeatLeader",
|
||||
@@ -90,7 +92,8 @@ const activities: Map<string, DiscordUserCardActivity[]> = new Map()
|
||||
},
|
||||
],
|
||||
} satisfies DiscordUserCardActivity,
|
||||
]).set("152155870917033985", [
|
||||
])
|
||||
.set("152155870917033985", [
|
||||
{
|
||||
type: ActivityType.Watching,
|
||||
name: "YouTube",
|
||||
|
||||
@@ -22,6 +22,7 @@ export const useExtensionStore = defineStore("extension", () => {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line unicorn/consistent-function-scoping
|
||||
function fetchPresences() {
|
||||
window.dispatchEvent(new CustomEvent("PreMiD_GetPresenceList"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user