This repository was archived by the owner on Nov 10, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
apps/worker/src/v4/fields Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { gql , UserInputError } from "apollo-server-core" ;
2+ import validator from "validator" ;
3+
4+ import { redis } from "../.." ;
5+
6+ export const schema = gql `
7+ type Mutation {
8+ addScience(
9+ identifier: String!
10+ presences: [String]
11+ os: String
12+ arch: String
13+ ): AddScienceResult
14+ }
15+
16+ type AddScienceResult {
17+ identifier: String
18+ presences: [String]
19+ os: String
20+ arch: String
21+ }
22+ ` ;
23+
24+ export async function resolver (
25+ _ : any ,
26+ params : { identifier : string ; presences : string [ ] ; os : string ; arch : string }
27+ ) {
28+ if ( ! validator . isUUID ( params . identifier , "4" ) )
29+ return new UserInputError ( "identifier must be a UUID v4." ) ;
30+
31+ const data = {
32+ identifier : params . identifier ,
33+ presences : params . presences . filter ( p => p . trim ( ) . length ) ,
34+ platform : {
35+ os : params . os ,
36+ arch : params . arch
37+ }
38+ } ;
39+
40+ await redis . hset (
41+ "pmd-api.scienceUpdates" ,
42+ params . identifier ,
43+ JSON . stringify ( data )
44+ ) ;
45+
46+ return data ;
47+ }
48+
49+ export const options = {
50+ type : "mutation"
51+ } ;
Original file line number Diff line number Diff line change 1+ import { gql , UserInputError } from "apollo-server-core" ;
2+ import validator from "validator" ;
3+
4+ import { redis } from "../.." ;
5+
6+ export const schema = gql `
7+ type Mutation {
8+ heartbeat(
9+ identifier: String!
10+ presence: HeartbeatPresenceInput
11+ extension: HeartbeatExtensionInput!
12+ ): HeartbeatResult
13+ }
14+
15+ input HeartbeatPresenceInput {
16+ service: String!
17+ verion: String!
18+ language: String!
19+ since: Float!
20+ }
21+
22+ input HeartbeatExtensionInput {
23+ version: String!
24+ language: String!
25+ connected: HeartbeatConnectedInput
26+ }
27+
28+ input HeartbeatConnectedInput {
29+ app: Int!
30+ discord: Boolean!
31+ }
32+
33+ type HeartbeatResult {
34+ identifier: String!
35+ presence: HeartbeatPresence
36+ extension: HeartbeatExtension!
37+ }
38+
39+ type HeartbeatPresence {
40+ service: String!
41+ verion: String!
42+ language: String!
43+ since: Float!
44+ }
45+
46+ type HeartbeatExtension {
47+ version: String!
48+ language: String!
49+ connected: HeartbeatConnected
50+ }
51+
52+ type HeartbeatConnected {
53+ app: Int!
54+ discord: Boolean!
55+ }
56+ ` ;
57+
58+ export async function resolver (
59+ _ : any ,
60+ params : {
61+ identifier : string ;
62+ presence ?: {
63+ service : string ;
64+ version : string ;
65+ language : string ;
66+ since : number ;
67+ } ;
68+ extension : {
69+ version : string ;
70+ language : string ;
71+ connected ?: {
72+ app : number ;
73+ discord : boolean ;
74+ } ;
75+ } ;
76+ }
77+ ) {
78+ if ( ! validator . isUUID ( params . identifier , "4" ) )
79+ return new UserInputError ( "identifier must be a UUID v4." ) ;
80+
81+ await redis . setex (
82+ `pmd-api.heartbeatUpdates.${ params . identifier } ` ,
83+ // 5 minutes
84+ 300 ,
85+ JSON . stringify ( params )
86+ ) ;
87+
88+ return params ;
89+ }
90+
91+ export const options = {
92+ type : "mutation"
93+ } ;
Original file line number Diff line number Diff line change 11{
2- "packageManager" : " pnpm@8.0.0 "
2+ "packageManager" : " pnpm@8.5.1 "
33}
You can’t perform that action at this time.
0 commit comments