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,33 @@
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
export const meta = {
requireCredential: true,
secure: true
};
export const paramDef = {
type: "object",
properties: {
scope: {
type: "array",
default: [],
items: {
type: "string",
pattern: /^[a-zA-Z0-9_]+$/.toString().slice(1, -1)
}
}
},
required: []
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
}).andWhere("item.scope = :scope", {
scope: ps.scope
});
const items = await query.getMany();
const res = {};
for (const item of items){
res[item.key] = item.value;
}
return res;
});
@@ -0,0 +1,50 @@
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
import { ApiError } from "../../../error.js";
export const meta = {
requireCredential: true,
secure: true,
errors: {
noSuchKey: {
message: "No such key.",
code: "NO_SUCH_KEY",
id: "97a1e8e7-c0f7-47d2-957a-92e61256e01a"
}
}
};
export const paramDef = {
type: "object",
properties: {
key: {
type: "string"
},
scope: {
type: "array",
default: [],
items: {
type: "string",
pattern: /^[a-zA-Z0-9_]+$/.toString().slice(1, -1)
}
}
},
required: [
"key"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
}).andWhere("item.key = :key", {
key: ps.key
}).andWhere("item.scope = :scope", {
scope: ps.scope
});
const item = await query.getOne();
if (item == null) {
throw new ApiError(meta.errors.noSuchKey);
}
return {
updatedAt: item.updatedAt,
value: item.value
};
});
@@ -0,0 +1,47 @@
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
import { ApiError } from "../../../error.js";
export const meta = {
requireCredential: true,
secure: true,
errors: {
noSuchKey: {
message: "No such key.",
code: "NO_SUCH_KEY",
id: "ac3ed68a-62f0-422b-a7bc-d5e09e8f6a6a"
}
}
};
export const paramDef = {
type: "object",
properties: {
key: {
type: "string"
},
scope: {
type: "array",
default: [],
items: {
type: "string",
pattern: /^[a-zA-Z0-9_]+$/.toString().slice(1, -1)
}
}
},
required: [
"key"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
}).andWhere("item.key = :key", {
key: ps.key
}).andWhere("item.scope = :scope", {
scope: ps.scope
});
const item = await query.getOne();
if (item == null) {
throw new ApiError(meta.errors.noSuchKey);
}
return item.value;
});
@@ -0,0 +1,34 @@
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
export const meta = {
requireCredential: true,
secure: true
};
export const paramDef = {
type: "object",
properties: {
scope: {
type: "array",
default: [],
items: {
type: "string",
pattern: /^[a-zA-Z0-9_]+$/.toString().slice(1, -1)
}
}
},
required: []
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
}).andWhere("item.scope = :scope", {
scope: ps.scope
});
const items = await query.getMany();
const res = {};
for (const item of items){
const type = typeof item.value;
res[item.key] = item.value === null ? "null" : Array.isArray(item.value) ? "array" : type === "number" ? "number" : type === "string" ? "string" : type === "boolean" ? "boolean" : type === "object" ? "object" : null;
}
return res;
});
@@ -0,0 +1,29 @@
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
export const meta = {
requireCredential: true,
secure: true
};
export const paramDef = {
type: "object",
properties: {
scope: {
type: "array",
default: [],
items: {
type: "string",
pattern: /^[a-zA-Z0-9_]+$/.toString().slice(1, -1)
}
}
},
required: []
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").select("item.key").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
}).andWhere("item.scope = :scope", {
scope: ps.scope
});
const items = await query.getMany();
return items.map((x)=>x.key);
});
@@ -0,0 +1,47 @@
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
import { ApiError } from "../../../error.js";
export const meta = {
requireCredential: true,
secure: true,
errors: {
noSuchKey: {
message: "No such key.",
code: "NO_SUCH_KEY",
id: "1fac4e8a-a6cd-4e39-a4a5-3a7e11f1b019"
}
}
};
export const paramDef = {
type: "object",
properties: {
key: {
type: "string"
},
scope: {
type: "array",
default: [],
items: {
type: "string",
pattern: /^[a-zA-Z0-9_]+$/.toString().slice(1, -1)
}
}
},
required: [
"key"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
}).andWhere("item.key = :key", {
key: ps.key
}).andWhere("item.scope = :scope", {
scope: ps.scope
});
const item = await query.getOne();
if (item == null) {
throw new ApiError(meta.errors.noSuchKey);
}
await RegistryItems.remove(item);
});
@@ -0,0 +1,23 @@
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
export const meta = {
requireCredential: true,
secure: true
};
export const paramDef = {
type: "object",
properties: {},
required: []
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").select("item.scope").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
});
const items = await query.getMany();
const res = [];
for (const item of items){
if (res.some((scope)=>scope.join(".") === item.scope.join("."))) continue;
res.push(item.scope);
}
return res;
});
@@ -0,0 +1,63 @@
import { publishMainStream } from "../../../../../services/stream.js";
import define from "../../../define.js";
import { RegistryItems } from "../../../../../models/index.js";
import { genId } from "../../../../../misc/gen-id.js";
export const meta = {
requireCredential: true,
secure: true
};
export const paramDef = {
type: "object",
properties: {
key: {
type: "string",
minLength: 1
},
value: {},
scope: {
type: "array",
default: [],
items: {
type: "string",
pattern: /^[a-zA-Z0-9_]+$/.toString().slice(1, -1)
}
}
},
required: [
"key",
"value"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const query = RegistryItems.createQueryBuilder("item").where("item.domain IS NULL").andWhere("item.userId = :userId", {
userId: user.id
}).andWhere("item.key = :key", {
key: ps.key
}).andWhere("item.scope = :scope", {
scope: ps.scope
});
const existingItem = await query.getOne();
if (existingItem) {
await RegistryItems.update(existingItem.id, {
updatedAt: new Date(),
value: ps.value
});
} else {
await RegistryItems.insert({
id: genId(),
createdAt: new Date(),
updatedAt: new Date(),
userId: user.id,
domain: null,
scope: ps.scope,
key: ps.key,
value: ps.value
});
}
// TODO: サードパーティアプリが傍受出来てしまうのでどうにかする
publishMainStream(user.id, "registryUpdated", {
scope: ps.scope,
key: ps.key,
value: ps.value
});
});