Fixed 267U.pre2

This commit is contained in:
2026-07-26 18:25:37 +09:00
parent 50bfaeafdf
commit 317d00a284
1286 changed files with 80222 additions and 1 deletions
@@ -0,0 +1,105 @@
import { fetchMeta } from "../../../../misc/fetch-meta.js";
import { genId } from "../../../../misc/gen-id.js";
import { SwSubscriptions } from "../../../../models/index.js";
import define from "../../define.js";
export const meta = {
tags: [
"account"
],
requireCredential: true,
description: "Register to receive push notifications.",
res: {
type: "object",
optional: false,
nullable: false,
properties: {
state: {
type: "string",
optional: true,
nullable: false,
enum: [
"already-subscribed",
"subscribed"
]
},
key: {
type: "string",
optional: false,
nullable: true
},
userId: {
type: "string",
optional: true,
nullable: false
},
endpoint: {
type: "string",
optional: false,
nullable: false
},
sendReadMessage: {
type: "boolean",
optional: false,
nullable: false
}
}
}
};
export const paramDef = {
type: "object",
properties: {
endpoint: {
type: "string"
},
auth: {
type: "string"
},
publickey: {
type: "string"
},
sendReadMessage: {
type: "boolean",
default: false
}
},
required: [
"endpoint",
"auth",
"publickey"
]
};
export default define(meta, paramDef, async (ps, me)=>{
const subscription = await SwSubscriptions.findOneBy({
userId: me.id,
endpoint: ps.endpoint,
auth: ps.auth,
publickey: ps.publickey
});
const instance = await fetchMeta(true);
// if already subscribed
if (subscription != null) {
return {
state: "already-subscribed",
key: instance.swPublicKey,
userId: me.id,
endpoint: subscription.endpoint,
sendReadMessage: subscription.sendReadMessage
};
}
await SwSubscriptions.insert({
id: genId(),
createdAt: new Date(),
userId: me.id,
endpoint: ps.endpoint,
auth: ps.auth,
publickey: ps.publickey,
sendReadMessage: ps.sendReadMessage
});
return {
state: "subscribed",
key: instance.swPublicKey,
userId: me.id,
endpoint: ps.endpoint,
sendReadMessage: ps.sendReadMessage
};
});
@@ -0,0 +1,57 @@
import { SwSubscriptions } from "../../../../models/index.js";
import define from "../../define.js";
export const meta = {
tags: [
"account"
],
requireCredential: true,
description: "Check push notification registration exists.",
res: {
type: "object",
optional: false,
nullable: true,
properties: {
userId: {
type: "string",
optional: false,
nullable: false
},
endpoint: {
type: "string",
optional: false,
nullable: false
},
sendReadMessage: {
type: "boolean",
optional: false,
nullable: false
}
}
}
};
export const paramDef = {
type: "object",
properties: {
endpoint: {
type: "string"
}
},
required: [
"endpoint"
]
};
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me)=>{
const subscription = await SwSubscriptions.findOneBy({
userId: me.id,
endpoint: ps.endpoint
});
if (subscription != null) {
return {
userId: subscription.userId,
endpoint: subscription.endpoint,
sendReadMessage: subscription.sendReadMessage
};
}
return null;
});
@@ -0,0 +1,28 @@
import { SwSubscriptions } from "../../../../models/index.js";
import define from "../../define.js";
export const meta = {
tags: [
"account"
],
requireCredential: false,
description: "Unregister from receiving push notifications."
};
export const paramDef = {
type: "object",
properties: {
endpoint: {
type: "string"
}
},
required: [
"endpoint"
]
};
export default define(meta, paramDef, async (ps, me)=>{
await SwSubscriptions.delete({
...me ? {
userId: me.id
} : {},
endpoint: ps.endpoint
});
});
@@ -0,0 +1,43 @@
import { SwSubscriptions } from "../../../../models/index.js";
import define from "../../define.js";
export const meta = {
tags: [
"account"
],
requireCredential: true,
description: "Unregister from receiving push notifications."
};
export const paramDef = {
type: "object",
properties: {
endpoint: {
type: "string"
},
sendReadMessage: {
type: "boolean"
}
},
required: [
"endpoint"
]
};
export default define(meta, paramDef, async (ps, me)=>{
const swSubscription = await SwSubscriptions.findOneBy({
userId: me.id,
endpoint: ps.endpoint
});
if (swSubscription === null) {
throw new Error("No such registration");
}
if (ps.sendReadMessage !== undefined) {
swSubscription.sendReadMessage = ps.sendReadMessage;
}
await SwSubscriptions.update(swSubscription.id, {
sendReadMessage: swSubscription.sendReadMessage
});
return {
userId: swSubscription.userId,
endpoint: swSubscription.endpoint,
sendReadMessage: swSubscription.sendReadMessage
};
});