Compare commits

..

105 commits

Author SHA1 Message Date
9f6be8d557
server: refactor meta caching
This removes the "caching" that re-fetches the instance meta information
from the database every 10 seconds.
2022-11-14 22:12:32 +01:00
9d9b2da6cc
fix parameter for cache fetcher 2022-11-13 20:31:24 +01:00
d1ec058d5c
server: refactor Cache to hold fetcher as attribute
Instead of having to pass the fetcher every time you want to fetch
something, the fetcher is stored in an attribute of the Cache.
2022-11-13 19:39:30 +01:00
131c12a30b
server: refactor prefetchEmojis
Exiting earlier might slightly improve performance.
2022-11-13 18:24:15 +01:00
8d6476af2a
server: remove localUserByIdCache
The same data is stored in userByIdCache. Whether a user is local or not
can easily be determined from the cached object.
2022-11-13 18:03:22 +01:00
57299f0df6
server: simplify caching for instance actor 2022-11-13 17:14:33 +01:00
b0489abd7f
translate japanese comments 2022-11-13 13:47:22 +01:00
26f1b66c6a
client: update API error dialog to error refactoring 2022-11-13 12:59:45 +01:00
1d877e97f0
client: fix maxlength for profile description
Changelog: Fixed
2022-11-13 11:58:11 +01:00
0571a0843c
client: improve suspend toggle 2022-11-13 01:12:05 +01:00
56033c26f0
service worker: remove dead code 2022-11-12 22:36:03 +01:00
80af8a143e
service worker: don't trigger "push notifications have been updated"
closes FoundKeyGang/FoundKey#121

Changelog: Fixed
2022-11-12 22:35:37 +01:00
a3468491a7
fix import 2022-11-12 18:51:57 +01:00
486be564e8
server: improve comments 2022-11-12 17:39:36 +01:00
c49f529ccb
server: use DeliverManager for user deletion 2022-11-12 15:23:49 +01:00
8979e779da
server: optimise follower inboxes query
Use the distinct query thingy so we don't have to make the Set work
so hard. This is also uniform code with the "everyone" above so should
hopefully be easier to understand.
2022-11-12 15:09:50 +01:00
Volpeon
b1bb5b28c5
client: remove wrong content type header 2022-11-12 09:43:24 +01:00
f3c38ad5c8
server: only add unique cascade-delete notes 2022-11-11 18:08:57 +01:00
899b01a031
remove unnecessary checks
These checks were made obsolete by commit
6df2f7c55c.
2022-11-11 18:07:49 +01:00
a27a29b371
server: redirect browsers to human readable page
Also added/translated more comments.
2022-11-11 17:54:11 +01:00
66a9d27ab1
server: increase user description length to 2048
Changelog: Changed
2022-11-11 12:28:57 +01:00
ed14fe8e79
client: remove hostname from signup & signin form
Long hostnames can obscure the username being entered. And the hostname
should already be known to the user anyway or they can find out by
looking at the current URL.

fixes <FoundKeyGang/FoundKey#231>

Changelog: Changed
2022-11-11 12:20:48 +01:00
d411ea6281
backend: make removeAds migration plain JS 2022-11-10 12:56:39 -05:00
5d23aa9e69
translate some comments to english 2022-11-10 00:36:39 +01:00
5b61941e4c
server: skip instances that proclaimed themself dead via HTTP 410
Changelog: Fixed
2022-11-10 00:23:30 +01:00
ca90cedba0
server: reduce dead instance detection to 7 days 2022-11-09 18:47:28 +01:00
2496b385ce
fix login
This is a fixup commit to b2c800e654.
2022-11-08 21:59:13 +01:00
54075789cd
server: remove content type bodge
Now that the client should send the proper content type, this should not be
necessary any more.
2022-11-08 20:57:38 +01:00
b2c800e654
client: properly set content-type header 2022-11-08 20:57:09 +01:00
5713f329ca
client: remove unnecessary ref 2022-11-08 20:57:08 +01:00
609312bb82
server: refactor errors in signin endpoint 2022-11-08 20:57:08 +01:00
7939d130aa backend: update sharp to 0.31.2
Changelog: Fixed
Fixes: FoundKeyGang/FoundKey#226
2022-11-08 01:16:55 -05:00
489eea0c67
server: improve API validation for creating apps
Resolves a FIXME comment.
2022-11-05 10:43:34 +01:00
6f65326b32
chore: synchronize code and database schema 2022-11-03 21:50:55 +01:00
408c5c3c65
improve description of generating migrations 2022-11-03 21:50:37 +01:00
e79d7879c6 docs/migrating: Make yarn instructions version-agnostic
This means we don't have to update the yarn version here in case we update the version of Yarn used.
2022-11-02 22:58:02 +00:00
e8ecd71f8a backend: refactor server/nodeinfo.ts (#221)
This fixes a few type errors like removing `software.respository` in
NodeInfo 2.0 and updating `metadata.repositoryUrl` to not use the
now removed meta `repositoryUrl` field.

Co-authored-by: Francis Dinh <normandy@biribiri.dev>
Reviewed-on: FoundKeyGang/FoundKey#221
2022-11-02 21:42:51 +00:00
0db0db9a87
backend: fix types in getRedisFamily 2022-10-31 18:39:05 -04:00
6df2f7c55c
server: refactor finding delete-cascaded notes
Remove the several filter functions in different places by filtering
directly in the database.

Instead of a QueryBuilder, use the plain find function.

Refactor a for loop awaiting several promises individually, use
Array.map and await Promise.all to make better use of promises.
2022-10-31 20:57:45 +01:00
ac240eb58d
server: translate/add comments 2022-10-31 20:57:18 +01:00
e27494cf3e
chore: Provide type for toggleReaction 2022-10-31 10:10:29 +01:00
d725f93d40
backend: Provide type for signedGet 2022-10-31 10:10:29 +01:00
6db9b76f46
Retouch types in server index 2022-10-31 10:10:29 +01:00
f50b04b015
Fix type errors in withPackedNote 2022-10-31 10:10:28 +01:00
3fe1f7e70e
Deal with withPackedNote(onNote) types in stream channels 2022-10-31 10:10:28 +01:00
eff9dbb5ee
Reassure typechecker about token in authenticate 2022-10-31 10:10:28 +01:00
fb80fd1fbd
Broaden type in authenticate as undefined is also nullable 2022-10-31 10:10:27 +01:00
2a33d0ac83
Fix type import in stream emitter typing 2022-10-31 10:10:27 +01:00
fb5f498641
Upgrade bull-board to unify misaligned types in its packages 2022-10-31 10:10:27 +01:00
23fbdfdf1f
Fix typos in syslog initialization 2022-10-31 10:10:26 +01:00
5b7a7794ab
backend: fix type of IEndpointMeta.errors
The errors array is supposed to be readonly.
2022-10-31 03:35:47 -04:00
bd0c06e2d0
server: fix RefereceError (again...) 2022-10-30 17:46:44 +01:00
c282ed7683
Narrow type of isPureRenote
As side effect of that, a non-null assertion can be removed.

Co-authored-by: Johann150 <johann.galle@protonmail.com>
2022-10-30 17:38:56 +01:00
47b2f619a6
client: fix follow button getting stuck processing
If a user on a remote instances changes their profile to manually accept
follow requests, this change may not immediately be federated. Because of
this, a user may get stuck seeing "processing".
2022-10-30 17:27:05 +01:00
240ad1cca6
server: fix ReferenceError
The super constructor has to be called before accessing this.
2022-10-30 16:22:12 +01:00
eb1ecd90e6
client: Add "follows you" pill to user profile popup
Changelog: Added
Reviewed-on: FoundKeyGang/FoundKey#217
2022-10-30 14:41:11 +01:00
14c7d2bf53
client: fix ternary statement
fixup for 4bfbe0dd96
2022-10-30 11:00:40 +01:00
4bfbe0dd96
client: refactor pagination.vue
This mostly involves deduplicating code and removing redudndant
statements.

Also translated all but one comment to English.
2022-10-29 23:09:35 +02:00
2aafe8fc9f
server: avoid adding suspended instances to deliver queue
This should reduce the performance hit when adding large numbers of
instances to the deliver queue by making the check for suspended and
dead instances a bulk operation.

Changelog: Changed
Reviewed-on: FoundKeyGang/FoundKey#215
2022-10-29 22:58:04 +02:00
7a64a3858d
fix erroneous quote 2022-10-28 23:49:30 +02:00
d0564759a5
server: remove unnecessary argument 2022-10-28 23:36:47 +02:00
253bffd974
API: refactor errors and improve documentation
Changelog: Changed
Reviewed-on: FoundKeyGang/FoundKey#214
2022-10-28 19:05:09 +02:00
735b9ab502
fix some lints 2022-10-28 16:57:56 +02:00
fb76843c19
adapt OpenAPI documentation generation to new error definitions 2022-10-27 22:44:06 +02:00
1dd935dc0c
fix endpoint type definition for errors 2022-10-27 22:44:06 +02:00
934ee82b8f
server: refactor ApiError to store error descriptions centrally
The UUIDs are no longer used for errors and all errors should now have
a descriptive message attached to them. Also, all errors should now have
the proper HTTP status code for a reply instead of the generic 400 and 500
response codes. Because the errors all have more specific error codes, the
"kind" of client or server is also abolished.
2022-10-27 22:43:58 +02:00
66d7b69377
server: refactor API handler and returning errors
This refactors the API handler to not use default exports, be async
instead of constructing a promise and modify how errors are returned.
2022-10-26 23:15:31 +02:00
c3c7164dfb
fix merge of #213 2022-10-26 22:53:06 +02:00
a991740e00
server: improve API definition for messaging/messages/create 2022-10-26 22:21:28 +02:00
4dc97d5b65
server: enhance reset-password endpoint
- Add a rate limit analogous to request-reset-password.
  See also a0ef32f4f6.
- Delete an expired reset request if found.
- Return a proper error.
- Use time constants.

Changelog: Changed
2022-10-26 22:12:38 +02:00
384e8c49b7
server: allow to like own gallery posts
Since you are also allowed to react to your own notes, it seems sensible
that you should be allowed to like your own gallery posts.

Analogous to commit 4c5aa9e538.

Changelog: Changed
2022-10-25 17:13:48 +02:00
Atsuko Karagi
c5e1c42d0a backend: require authentification for fetch-rss
Changelog: Changed
2022-10-25 08:56:34 -04:00
Atsuko Karagi
f74395c386 backend: remove unused endpoints
Changelog: Removed
2022-10-25 08:56:31 -04:00
Atsuko Karagi
b2c483faf5 backend: tweak endpoint permissions
Changelog: Changed
2022-10-25 08:36:39 -04:00
Atsuko Karagi
5bf1e5ad71 backend: federation information requires auth
Changelog: Changed
2022-10-25 08:36:37 -04:00
cd55d7a56f chore: improve contributing release guidelines 2022-10-25 08:35:42 -04:00
a0ef32f4f6
server: properly delete expired password reset requests
Changelog: Fixed
2022-10-23 23:09:11 +02:00
ba911dab65 Update 'docs/migrating.md' 2022-10-22 17:49:50 +00:00
7ec8729d90
backend: fix lint error in remove-note.ts 2022-10-21 17:52:15 -04:00
f97e990ed3 Remove deleted files/dirs from dockerignore
Much of them were deleted since they only apply to github, so there's no need to ignore them anymore.
2022-10-21 19:39:16 +00:00
c36cca30cb Merge pull request 'backend: Fix various lints in services/note' (#206) from backend-services-note into main
Reviewed-on: FoundKeyGang/FoundKey#206
2022-10-21 19:29:41 +00:00
43644494d3
translate remaining comments 2022-10-21 13:33:03 -04:00
923c93da12
use await for notes.countBy 2022-10-20 21:22:52 -04:00
aa1e4d0fbc
change null assertion ternaries to use optional chaining 2022-10-20 21:22:52 -04:00
bfba54524d
backend: fix various type lints in services/note
`createdAt` in `insertNote` now will default to the current date.

Also refactor poll insert:
Instead of testing hasPoll, just do a null check on data.poll since it's
a more reliable indicator for whether a poll exists (and also tsc won't
complain about data.poll being possibly null).
2022-10-20 21:22:24 -04:00
d83c1c3851
backend: use named exports for services/note 2022-10-20 21:16:34 -04:00
3da7221eec
backend: mark elasticsearch as optional 2022-10-20 21:15:48 -04:00
9544cd69d2
fix typo 2022-10-20 21:26:12 +02:00
b359b01700
improve docs 2022-10-20 21:22:34 +02:00
cfb8723618
fix API definitions 2022-10-20 20:40:48 +02:00
ee70ad52fc
server: error when trying to unclip note that is not clipped
When a note is not added to a clip and an API call tries to remove the note
from that clip, the API will now raise an error.

Changelog: Changed
2022-10-19 21:54:37 +02:00
4c5aa9e538
server: allow to like own pages
Since you are also allowed to react to your own notes, it seems sensible
that you should be allowed to like your own pages.

Changelog: Changed
2022-10-19 21:52:43 +02:00
4b6c3b2f37
properly await promise 2022-10-19 15:26:37 +02:00
fbf7ea07c9
server refactor: centrally load locale
To reduce code duplication, the locales are loaded in @/misc/i18n.ts
directly instead of importing it in each file using it separately.
2022-10-19 12:30:23 +02:00
507dede6da
default to english instead of japanese 2022-10-19 09:25:38 +02:00
f0f673843e
refactor API console
Refactor to use $ref sugar.

Also forego the API call to fetch endpoint information if the endpoint
name is not in the list of available endpoints that has already been
fetched.
2022-10-18 22:04:42 +02:00
fed41d8d15
fix API console 2022-10-18 22:00:40 +02:00
7257338077 backend: make max note length configurable (#210)
Changelog: Added
Closes: FoundKeyGang/FoundKey#208
Co-authored-by: Francis Dinh <normandy@biribiri.dev>
Reviewed-on: FoundKeyGang/FoundKey#210
2022-10-18 17:33:00 +00:00
3aa1d3bf97
backend: update DB_MAX_IMAGE_COMMENT_LENGTH
This was increased to 2048 characters in
186d693385.
2022-10-17 17:49:48 -04:00
f4ee8b321e
client refactor: use pagination in drive component
Squashed commit of the following:

commit 8636adab6455bea29659a6799a7f3aad9e7cc10d
Author: Johann150 <johann.galle@protonmail.com>
Date:   Mon Oct 17 22:53:24 2022 +0200

    fix: remove comment

commit 7ff8d45bfa2ed5c07c9a053e817604ef2eb115ad
Author: Johann150 <johann.galle@protonmail.com>
Date:   Mon Oct 17 21:55:48 2022 +0200

    fix paginations reloading

    The Pagination type actually specifies that just the params property
    should be a Ref.

commit 55fe9210c15785611603e3a7a2535ebf8008ea64
Author: Johann150 <johann.galle@protonmail.com>
Date:   Mon Oct 17 18:55:54 2022 +0200

    fix variable name

commit a464d1363bc8c62606a4d2acc148ce269973bede
Author: Johann150 <johann.galle@protonmail.com>
Date:   Sun Oct 16 22:36:11 2022 +0200

    fix: don't display empty drive message while loading

commit 52905b398f683ff3c71c2d5592851b2d2a428550
Author: Johann150 <johann.galle@protonmail.com>
Date:   Fri Oct 14 22:19:13 2022 +0200

    remove unavailable i18n strings

commit d491a71cbec05f991864a06b8e0001d40da006a3
Author: Johann150 <johann.galle@protonmail.com>
Date:   Fri Oct 14 22:18:42 2022 +0200

    client refactor: use pagination in drive component

    This majorly refactors the drive component to use the proper pagination
    component instead of reimplementing pagination.

    The drive component is also refactored to use ref sugar (i.e. $ref).
2022-10-17 22:58:12 +02:00
04d4dd323f
backend: use time constant in services/chart/index.ts 2022-10-16 18:22:18 -04:00
e814fdc7d1
backend: fix lints in services/drive 2022-10-16 18:20:20 -04:00
f2f547172e
backend: improve documentation of pin/update functions 2022-10-16 18:06:22 -04:00
f17485d8a2
backend: add type annotations to delete.ts 2022-10-16 17:14:30 -04:00
70eec26b74
bump versions in all package.json files 2022-10-16 11:46:12 -04:00
277 changed files with 2373 additions and 3874 deletions

View file

@ -124,6 +124,9 @@ redis:
# Upload or download file size limits (bytes)
#maxFileSize: 262144000
# Max note text length (in characters)
#maxNoteTextLength: 3000
#allowedPrivateNetworks: [
# '127.0.0.1/32'
#]

View file

@ -1,6 +1,4 @@
.autogen
.github
.travis
.vscode
.config
Dockerfile
@ -12,4 +10,3 @@ elasticsearch/
node_modules/
redis/
files/
misskey-assets/

View file

@ -139,6 +139,14 @@ To generate the changelog, we use a standard shortlog command: `git shortlog --f
The person performing the release process should build the next CHANGELOG section based on this output, not use it as-is.
Full releases should also remove any pre-release CHANGELOG sections.
Here is the step by step checklist:
1. If **stable** release, announce the comment period. Restart the comment period if a blocker bug is found and fixed.
2. Edit various `package.json`s to the new version.
3. Write a new entry into the changelog.
You should use the `git shortlog --format='%h %s' --group=trailer:changelog LAST_TAG..` command to get general data,
then rewrite it in a human way.
4. Tag the commit with the changes in 2 and 3 (if together, else the latter).
## Translation
[![Translation status](http://translate.akkoma.dev/widgets/foundkey/-/svg-badge.svg)](http://translate.akkoma.dev/engage/foundkey/)
@ -289,8 +297,11 @@ PostgreSQL array indices **start at 1**.
When `IN` is performed on a column that may contain `NULL` values, use `OR` or similar to handle `NULL` values.
### creating migrations
In `packages/backend`, run:
First make changes to the entity files in `packages/backend/src/models/entities/`.
Then, in `packages/backend`, run:
```sh
yarn build
npx typeorm migration:generate -d ormconfig.js -o <migration name>
```

View file

@ -40,6 +40,9 @@ git merge tags/v13.0.0-preview2 --squash
# you are now on the "next" release
```
## Making sure modern Yarn works
Foundkey uses Modern Yarn instead of Classic (1.x). To make sure the `yarn` command will work going forward, run `corepack enable`.
## Rebuilding and running database migrations
This will be pretty much the same as a regular update of Misskey. Note that `yarn install` may take a while since dependency versions have been updated or removed and we use a newer version of Yarn.
```sh

View file

@ -190,7 +190,9 @@ charts: "Charts"
perHour: "Per Hour"
perDay: "Per Day"
stopActivityDelivery: "Stop sending activities"
stopActivityDeliveryDescription: "Local activities will not be sent to this instance. Receiving activities works as before."
blockThisInstance: "Block this instance"
blockThisInstanceDescription: "Local activites will not be sent to this instance. Activites from this instance will be discarded."
operations: "Operations"
software: "Software"
version: "Version"

View file

@ -1,6 +1,6 @@
{
"name": "foundkey",
"version": "13.0.0-preview.1",
"version": "13.0.0-preview2",
"repository": {
"type": "git",
"url": "https://akkoma.dev/FoundKeyGang/FoundKey.git"

View file

@ -1,5 +1,5 @@
export class removeAds1657570176749 {
name = 'removeAds1657570176749'
name = 'removeAds1657570176749';
async up(queryRunner) {
await queryRunner.query(`DROP TABLE "ad"`);

View file

@ -0,0 +1,44 @@
export class sync1667503570994 {
name = 'sync1667503570994'
async up(queryRunner) {
await Promise.all([
// the migration for renote mutes added the index to the wrong table
queryRunner.query(`DROP INDEX "public"."IDX_renote_muting_createdAt"`),
queryRunner.query(`DROP INDEX "public"."IDX_renote_muting_muteeId"`),
queryRunner.query(`DROP INDEX "public"."IDX_renote_muting_muterId"`),
queryRunner.query(`CREATE INDEX "IDX_d1259a2c2b7bb413ff449e8711" ON "renote_muting" ("createdAt") `),
queryRunner.query(`CREATE INDEX "IDX_7eac97594bcac5ffcf2068089b" ON "renote_muting" ("muteeId") `),
queryRunner.query(`CREATE INDEX "IDX_7aa72a5fe76019bfe8e5e0e8b7" ON "renote_muting" ("muterId") `),
queryRunner.query(`COMMENT ON COLUMN "renote_muting"."createdAt" IS 'The created date of the Muting.'`),
queryRunner.query(`COMMENT ON COLUMN "renote_muting"."muteeId" IS 'The mutee user ID.'`),
queryRunner.query(`COMMENT ON COLUMN "renote_muting"."muterId" IS 'The muter user ID.'`),
queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "text" SET NOT NULL`),
queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "text" SET DEFAULT ''`),
queryRunner.query(`CREATE UNIQUE INDEX "IDX_0d801c609cec4e9eb4b6b4490c" ON "renote_muting" ("muterId", "muteeId") `),
queryRunner.query(`ALTER TABLE "renote_muting" ADD CONSTRAINT "FK_7eac97594bcac5ffcf2068089b6" FOREIGN KEY ("muteeId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`),
queryRunner.query(`ALTER TABLE "renote_muting" ADD CONSTRAINT "FK_7aa72a5fe76019bfe8e5e0e8b7d" FOREIGN KEY ("muterId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`),
]);
}
async down(queryRunner) {
await Promise.all([
queryRunner.query(`ALTER TABLE "renote_muting" DROP CONSTRAINT "FK_7aa72a5fe76019bfe8e5e0e8b7d"`),
queryRunner.query(`ALTER TABLE "renote_muting" DROP CONSTRAINT "FK_7eac97594bcac5ffcf2068089b6"`),
queryRunner.query(`DROP INDEX "public"."IDX_0d801c609cec4e9eb4b6b4490c"`),
queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "text" DROP DEFAULT`),
queryRunner.query(`ALTER TABLE "page" ALTER COLUMN "text" DROP NOT NULL`),
queryRunner.query(`COMMENT ON COLUMN "renote_muting"."muterId" IS NULL`),
queryRunner.query(`COMMENT ON COLUMN "renote_muting"."muteeId" IS NULL`),
queryRunner.query(`COMMENT ON COLUMN "renote_muting"."createdAt" IS NULL`),
queryRunner.query(`DROP INDEX "public"."IDX_7aa72a5fe76019bfe8e5e0e8b7"`),
queryRunner.query(`DROP INDEX "public"."IDX_7eac97594bcac5ffcf2068089b"`),
queryRunner.query(`DROP INDEX "public"."IDX_d1259a2c2b7bb413ff449e8711"`),
queryRunner.query(`CREATE INDEX "IDX_renote_muting_muterId" ON "muting" ("muterId") `),
queryRunner.query(`CREATE INDEX "IDX_renote_muting_muteeId" ON "muting" ("muteeId") `),
queryRunner.query(`CREATE INDEX "IDX_renote_muting_createdAt" ON "muting" ("createdAt") `),
]);
}
}

View file

@ -1,6 +1,6 @@
{
"name": "backend",
"version": "13.0.0-preview1",
"version": "13.0.0-preview2",
"main": "./index.js",
"private": true,
"type": "module",
@ -15,8 +15,8 @@
"test": "npm run mocha"
},
"dependencies": {
"@bull-board/api": "^4.2.2",
"@bull-board/koa": "4.0.0",
"@bull-board/api": "^4.3.1",
"@bull-board/koa": "^4.3.1",
"@discordapp/twemoji": "14.0.2",
"@elastic/elasticsearch": "7.11.0",
"@koa/cors": "3.1.0",
@ -96,7 +96,7 @@
"rss-parser": "3.12.0",
"sanitize-html": "2.7.0",
"semver": "7.3.7",
"sharp": "0.30.7",
"sharp": "0.31.2",
"speakeasy": "2.0.0",
"strict-event-emitter-types": "2.0.0",
"stringz": "2.1.0",

View file

@ -38,6 +38,8 @@ export default function load(): Config {
config.port = config.port || parseInt(process.env.PORT || '', 10);
if (!config.maxNoteTextLength) config.maxNoteTextLength = 3000;
mixin.version = meta.version;
mixin.host = url.host;
mixin.hostname = url.hostname;

View file

@ -10,7 +10,7 @@ function getRedisFamily(family?: string | number): number {
dual: 0,
};
if (typeof family === 'string' && family in familyMap) {
return familyMap[family];
return familyMap[family as keyof typeof familyMap];
} else if (typeof family === 'number' && Object.values(familyMap).includes(family)) {
return family;
}

View file

@ -24,7 +24,7 @@ export type Source = {
db?: number;
prefix?: string;
};
elasticsearch: {
elasticsearch?: {
host: string;
port: number;
ssl?: boolean;
@ -41,6 +41,8 @@ export type Source = {
maxFileSize?: number;
maxNoteTextLength?: number;
accesslog?: string;
clusterLimit?: number;

View file

@ -1,5 +1,3 @@
export const MAX_NOTE_TEXT_LENGTH = 3000;
// Time constants
export const SECOND = 1000;
export const MINUTE = 60 * SECOND;

View file

@ -62,22 +62,21 @@ export function fromHtml(html: string, hashtagNames?: string[]): string {
const rel = node.attrs.find(x => x.name === 'rel');
const href = node.attrs.find(x => x.name === 'href');
// ハッシュタグ
// hashtags
if (hashtagNames && href && hashtagNames.map(x => x.toLowerCase()).includes(txt.toLowerCase())) {
text += txt;
// メンション
// mentions
} else if (txt.startsWith('@') && !(rel && rel.value.match(/^me /))) {
const part = txt.split('@');
if (part.length === 2 && href) {
//#region ホスト名部分が省略されているので復元する
// restore the host name part
const acct = `${txt}@${(new URL(href.value)).hostname}`;
text += acct;
//#endregion
} else if (part.length === 3) {
text += txt;
}
// その他
// other
} else {
const generateLink = () => {
if (!href && !txt) {

View file

@ -1,10 +1,12 @@
export class Cache<T> {
public cache: Map<string | null, { date: number; value: T; }>;
private lifetime: number;
public fetcher: (key: string | null) => Promise<T | undefined>;
constructor(lifetime: Cache<never>['lifetime']) {
constructor(lifetime: number, fetcher: Cache<T>['fetcher']) {
this.cache = new Map();
this.lifetime = lifetime;
this.fetcher = fetcher;
}
public set(key: string | null, value: T): void {
@ -17,10 +19,13 @@ export class Cache<T> {
public get(key: string | null): T | undefined {
const cached = this.cache.get(key);
if (cached == null) return undefined;
// discard if past the cache lifetime
if ((Date.now() - cached.date) > this.lifetime) {
this.cache.delete(key);
return undefined;
}
return cached.value;
}
@ -29,52 +34,22 @@ export class Cache<T> {
}
/**
* fetcherを呼び出して結果をキャッシュ&
* optional: キャッシュが存在してもvalidatorでfalseを返すとキャッシュ無効扱いにします
* If the value is cached, it is returned. Otherwise the fetcher is
* run to get the value. If the fetcher returns undefined, it is
* returned but not cached.
*/
public async fetch(key: string | null, fetcher: () => Promise<T>, validator?: (cachedValue: T) => boolean): Promise<T> {
const cachedValue = this.get(key);
if (cachedValue !== undefined) {
if (validator) {
if (validator(cachedValue)) {
// Cache HIT
return cachedValue;
}
public async fetch(key: string | null): Promise<T | undefined> {
const cached = this.get(key);
if (cached !== undefined) {
return cached;
} else {
// Cache HIT
return cachedValue;
}
}
const value = await this.fetcher(key);
// Cache MISS
const value = await fetcher();
// don't cache undefined
if (value !== undefined)
this.set(key, value);
return value;
}
/**
* fetcherを呼び出して結果をキャッシュ&
* optional: キャッシュが存在してもvalidatorでfalseを返すとキャッシュ無効扱いにします
*/
public async fetchMaybe(key: string | null, fetcher: () => Promise<T | undefined>, validator?: (cachedValue: T) => boolean): Promise<T | undefined> {
const cachedValue = this.get(key);
if (cachedValue !== undefined) {
if (validator) {
if (validator(cachedValue)) {
// Cache HIT
return cachedValue;
}
} else {
// Cache HIT
return cachedValue;
}
}
// Cache MISS
const value = await fetcher();
if (value !== undefined) {
this.set(key, value);
}
return value;
}
}
}

View file

@ -3,22 +3,26 @@ import { Note } from '@/models/entities/note.js';
import { User } from '@/models/entities/user.js';
import { UserListJoinings, UserGroupJoinings, Blockings } from '@/models/index.js';
import * as Acct from '@/misc/acct.js';
import { MINUTE } from '@/const.js';
import { getFullApAccount } from './convert-host.js';
import { Packed } from './schema.js';
import { Cache } from './cache.js';
const blockingCache = new Cache<User['id'][]>(1000 * 60 * 5);
const blockingCache = new Cache<User['id'][]>(
5 * MINUTE,
(blockerId) => Blockings.findBy({ blockerId }).then(res => res.map(x => x.blockeeId)),
);
// NOTE: フォローしているユーザーのノート、リストのユーザーのノート、グループのユーザーのノート指定はパフォーマンス上の理由で無効になっている
// designation for users you follow, list users and groups is disabled for performance reasons
/**
* noteUserFollowers / antennaUserFollowing
* either noteUserFollowers or antennaUserFollowing must be specified
*/
export async function checkHitAntenna(antenna: Antenna, note: (Note | Packed<'Note'>), noteUser: { id: User['id']; username: string; host: string | null; }, noteUserFollowers?: User['id'][], antennaUserFollowing?: User['id'][]): Promise<boolean> {
if (note.visibility === 'specified') return false;
// アンテナ作成者がノート作成者にブロックされていたらスキップ
const blockings = await blockingCache.fetch(noteUser.id, () => Blockings.findBy({ blockerId: noteUser.id }).then(res => res.map(x => x.blockeeId)));
// skip if the antenna creator is blocked by the note author
const blockings = await blockingCache.fetch(noteUser.id);
if (blockings.some(blocking => blocking === antenna.userId)) return false;
if (note.visibility === 'followers') {

View file

@ -1,44 +1,44 @@
import push from 'web-push';
import { db } from '@/db/postgre.js';
import { Meta } from '@/models/entities/meta.js';
import { getFetchInstanceMetadataLock } from '@/misc/app-lock.js';
let cache: Meta;
export async function fetchMeta(noCache = false): Promise<Meta> {
if (!noCache && cache) return cache;
/**
* Performs the primitive database operation to set the server configuration
*/
export async function setMeta(meta: Meta): Promise<void> {
const unlock = await getFetchInstanceMetadataLock('localhost');
return await db.transaction(async transactionalEntityManager => {
// 過去のバグでレコードが複数出来てしまっている可能性があるので新しいIDを優先する
const metas = await transactionalEntityManager.find(Meta, {
// try to mitigate older bugs where multiple meta entries may have been created
db.manager.clear(Meta);
db.manager.insert(Meta, meta);
unlock();
}
/**
* Performs the primitive database operation to fetch server configuration.
* Writes to `cache` instead of returning.
*/
async function getMeta(): Promise<void> {
const unlock = await getFetchInstanceMetadataLock('localhost');
// new IDs are prioritised because multiple records may have been created due to past bugs
cache = db.manager.findOne(Meta, {
order: {
id: 'DESC',
},
});
const meta = metas[0];
if (meta) {
cache = meta;
return meta;
} else {
// metaが空のときfetchMetaが同時に呼ばれるとここが同時に呼ばれてしまうことがあるのでフェイルセーフなupsertを使う
const saved = await transactionalEntityManager
.upsert(
Meta,
{
id: 'x',
},
['id'],
)
.then((x) => transactionalEntityManager.findOneByOrFail(Meta, x.identifiers[0]));
cache = saved;
return saved;
}
});
unlock();
}
setInterval(() => {
fetchMeta(true).then(meta => {
cache = meta;
});
}, 1000 * 10);
export async function fetchMeta(noCache = false): Promise<Meta> {
if (!noCache && cache) return cache;
await getMeta();
return cache;
}

View file

@ -11,4 +11,4 @@ export const DB_MAX_NOTE_TEXT_LENGTH = 8192;
* Maximum image description length that can be stored in DB.
* Surrogate pairs count as one
*/
export const DB_MAX_IMAGE_COMMENT_LENGTH = 512;
export const DB_MAX_IMAGE_COMMENT_LENGTH = 2048;

View file

@ -1,19 +1,18 @@
export class I18n<T extends Record<string, any>> {
public locale: T;
const locales = await import('../../../../locales/index.js').then(mod => mod.default);
constructor(locale: T) {
this.locale = locale;
export class I18n {
public ts: Record<string, any>;
//#region BIND
constructor(locale: string) {
this.ts = locales[locale];
this.t = this.t.bind(this);
//#endregion
}
// string にしているのは、ドット区切りでのパス指定を許可するため
// なるべくこのメソッド使うよりもlocale直接参照の方がvueのキャッシュ効いてパフォーマンスが良いかも
public t(key: string, args?: Record<string, any>): string {
try {
let str = key.split('.').reduce((o, i) => o[i], this.locale) as string;
let str = key.split('.').reduce((o, i) => o[i], this.ts) as string;
if (args) {
for (const [k, v] of Object.entries(args)) {

View file

@ -3,8 +3,11 @@ import { User } from '@/models/entities/user.js';
import { UserKeypair } from '@/models/entities/user-keypair.js';
import { Cache } from './cache.js';
const cache = new Cache<UserKeypair>(Infinity);
const cache = new Cache<UserKeypair>(
Infinity,
(userId) => UserKeypairs.findOneByOrFail({ userId }),
);
export async function getUserKeypair(userId: User['id']): Promise<UserKeypair> {
return await cache.fetch(userId, () => UserKeypairs.findOneByOrFail({ userId }));
return await cache.fetch(userId);
}

View file

@ -4,14 +4,27 @@ import { Emojis } from '@/models/index.js';
import { Emoji } from '@/models/entities/emoji.js';
import { Note } from '@/models/entities/note.js';
import { query } from '@/prelude/url.js';
import { HOUR } from '@/const.js';
import { Cache } from './cache.js';
import { isSelfHost, toPunyNullable } from './convert-host.js';
import { decodeReaction } from './reaction-lib.js';
const cache = new Cache<Emoji | null>(1000 * 60 * 60 * 12);
/**
* composite cache key: `${host ?? ''}:${name}`
*/
const cache = new Cache<Emoji | null>(
12 * HOUR,
async (key) => {
const [host, name] = key.split(':');
return (await Emojis.findOneBy({
name,
host: host || IsNull(),
})) || null;
},
);
/**
*
* Information needed to attach in ActivityPub
*/
type PopulatedEmoji = {
name: string;
@ -36,28 +49,22 @@ function parseEmojiStr(emojiName: string, noteUserHost: string | null) {
const name = match[1];
// ホスト正規化
const host = toPunyNullable(normalizeHost(match[2], noteUserHost));
return { name, host };
}
/**
*
* @param emojiName (:, @. (decodeReactionで可能))
* @param noteUserHost
* @returns , nullは未マッチを意味する
* Resolve emoji information from ActivityPub attachment.
* @param emojiName custom emoji names attached to notes, user profiles or in rections. Colons should not be included. Localhost is denote by @. (see also `decodeReaction`)
* @param noteUserHost host that the content is from, to default to
* @returns emoji information. `null` means not found.
*/
export async function populateEmoji(emojiName: string, noteUserHost: string | null): Promise<PopulatedEmoji | null> {
const { name, host } = parseEmojiStr(emojiName, noteUserHost);
if (name == null) return null;
const queryOrNull = async () => (await Emojis.findOneBy({
name,
host: host ?? IsNull(),
})) || null;
const emoji = await cache.fetch(`${name} ${host}`, queryOrNull);
const emoji = await cache.fetch(`${host ?? ''}:${name}`);
if (emoji == null) return null;
@ -72,7 +79,7 @@ export async function populateEmoji(emojiName: string, noteUserHost: string | nu
}
/**
* (, )
* Retrieve list of emojis from the cache. Uncached emoji are dropped.
*/
export async function populateEmojis(emojiNames: string[], noteUserHost: string | null): Promise<PopulatedEmoji[]> {
const emojis = await Promise.all(emojiNames.map(x => populateEmoji(x, noteUserHost)));
@ -103,11 +110,20 @@ export function aggregateNoteEmojis(notes: Note[]) {
}
/**
*
* Query list of emojis in bulk and add them to the cache.
*/
export async function prefetchEmojis(emojis: { name: string; host: string | null; }[]): Promise<void> {
const notCachedEmojis = emojis.filter(emoji => cache.get(`${emoji.name} ${emoji.host}`) == null);
const notCachedEmojis = emojis.filter(emoji => {
// check if the cache has this emoji
return cache.get(`${emoji.host ?? ''}:${emoji.name}`) == null;
});
// check if there even are any uncached emoji to handle
if (notCachedEmojis.length === 0) return;
// query all uncached emoji
const emojisQuery: any[] = [];
// group by hosts to try to reduce query size
const hosts = new Set(notCachedEmojis.map(e => e.host));
for (const host of hosts) {
emojisQuery.push({
@ -115,11 +131,14 @@ export async function prefetchEmojis(emojis: { name: string; host: string | null
host: host ?? IsNull(),
});
}
const _emojis = emojisQuery.length > 0 ? await Emojis.find({
await Emojis.find({
where: emojisQuery,
select: ['name', 'host', 'originalUrl', 'publicUrl'],
}) : [];
for (const emoji of _emojis) {
cache.set(`${emoji.name} ${emoji.host}`, emoji);
}
}).then(emojis => {
// store all emojis into the cache
emojis.forEach(emoji => {
cache.set(`${emoji.host ?? ''}:${emoji.name}`, emoji);
});
});
}

View file

@ -1,5 +1,5 @@
import { Note } from '@/models/entities/note.js';
export function isPureRenote(note: Note): boolean {
export function isPureRenote(note: Note): note is Note & { renoteId: string, text: null, fileIds: null | never[], hasPoll: false } {
return note.renoteId != null && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !note.hasPoll;
}

View file

@ -0,0 +1,55 @@
import { Brackets } from 'typeorm';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { Instances } from '@/models/index.js';
import { Instance } from '@/models/entities/instance.js';
import { DAY } from '@/const.js';
// Threshold from last contact after which an instance will be considered
// "dead" and should no longer get activities delivered to it.
const deadThreshold = 7 * DAY;
/**
* Returns the subset of hosts which should be skipped.
*
* @param hosts array of punycoded instance hosts
* @returns array of punycoed instance hosts that should be skipped (subset of hosts parameter)
*/
export async function skippedInstances(hosts: Array<Instace['host']>): Array<Instance['host']> {
// first check for blocked instances since that info may already be in memory
const { blockedHosts } = await fetchMeta();
const skipped = hosts.filter(host => blockedHosts.includes(host));
// if possible return early and skip accessing the database
if (skipped.length === hosts.length) return hosts;
const deadTime = new Date(Date.now() - deadThreshold);
return skipped.concat(
await Instances.createQueryBuilder('instance')
.where('instance.host in (:...hosts)', {
// don't check hosts again that we already know are suspended
// also avoids adding duplicates to the list
hosts: hosts.filter(host => !skipped.includes(host)),
})
.andWhere(new Brackets(qb => { qb
.where('instance.isSuspended')
.orWhere('instance.lastCommunicatedAt < :deadTime', { deadTime })
.orWhere('instance.latestStatus = 410');
}))
.select('host')
.getRawMany()
);
}
/**
* Returns whether a specific host (punycoded) should be skipped.
* Convenience wrapper around skippedInstances which should only be used if there is a single host to check.
* If you have multiple hosts, consider using skippedInstances instead to do a bulk check.
*
* @param host punycoded instance host
* @returns whether the given host should be skipped
*/
export async function shouldSkipInstance(host: Instance['host']): boolean {
const skipped = await skippedInstances([host]);
return skipped.length > 0;
}

View file

@ -62,7 +62,8 @@ export class DriveFile {
public size: number;
@Column('varchar', {
length: 512, nullable: true,
length: 2048,
nullable: true,
comment: 'The comment of the DriveFile.',
})
public comment: string | null;

View file

@ -7,7 +7,7 @@ export class Instance {
public id: string;
/**
*
* Date and time this instance was first seen.
*/
@Index()
@Column('timestamp with time zone', {
@ -16,7 +16,7 @@ export class Instance {
public caughtAt: Date;
/**
*
* Hostname
*/
@Index({ unique: true })
@Column('varchar', {
@ -26,7 +26,7 @@ export class Instance {
public host: string;
/**
*
* Number of users on this instance.
*/
@Column('integer', {
default: 0,
@ -35,7 +35,7 @@ export class Instance {
public usersCount: number;
/**
* 稿
* Number of notes on this instance.
*/
@Column('integer', {
default: 0,
@ -44,7 +44,7 @@ export class Instance {
public notesCount: number;
/**
*
* Number of local users who are followed by users from this instance.
*/
@Column('integer', {
default: 0,
@ -52,7 +52,7 @@ export class Instance {
public followingCount: number;
/**
*
* Number of users from this instance who are followed by local users.
*/
@Column('integer', {
default: 0,
@ -60,7 +60,7 @@ export class Instance {
public followersCount: number;
/**
*
* Timestamp of the latest outgoing HTTP request.
*/
@Column('timestamp with time zone', {
nullable: true,
@ -68,7 +68,7 @@ export class Instance {
public latestRequestSentAt: Date | null;
/**
* HTTPステータスコード
* HTTP status code that was received for the last outgoing HTTP request.
*/
@Column('integer', {
nullable: true,
@ -76,7 +76,7 @@ export class Instance {
public latestStatus: number | null;
/**
*
* Timestamp of the latest incoming HTTP request.
*/
@Column('timestamp with time zone', {
nullable: true,
@ -84,13 +84,13 @@ export class Instance {
public latestRequestReceivedAt: Date | null;
/**
*
* Timestamp of last communication with this instance (incoming or outgoing).
*/
@Column('timestamp with time zone')
public lastCommunicatedAt: Date;
/**
*
* Whether this instance seems unresponsive.
*/
@Column('boolean', {
default: false,
@ -98,7 +98,7 @@ export class Instance {
public isNotResponding: boolean;
/**
*
* Whether sending activities to this instance has been suspended.
*/
@Index()
@Column('boolean', {

View file

@ -6,13 +6,16 @@ import { Packed } from '@/misc/schema.js';
import { awaitAll, Promiseable } from '@/prelude/await-all.js';
import { populateEmojis } from '@/misc/populate-emojis.js';
import { getAntennas } from '@/misc/antenna-cache.js';
import { USER_ACTIVE_THRESHOLD, USER_ONLINE_THRESHOLD } from '@/const.js';
import { USER_ACTIVE_THRESHOLD, USER_ONLINE_THRESHOLD, HOUR } from '@/const.js';
import { Cache } from '@/misc/cache.js';
import { db } from '@/db/postgre.js';
import { Instance } from '../entities/instance.js';
import { Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, RenoteMutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, AntennaNotes, ChannelFollowings, Instances, DriveFiles } from '../index.js';
const userInstanceCache = new Cache<Instance | null>(1000 * 60 * 60 * 3);
const userInstanceCache = new Cache<Instance | null>(
3 * HOUR,
(host) => Instances.findOneBy({ host }).then(x => x ?? undefined),
);
type IsUserDetailed<Detailed extends boolean> = Detailed extends true ? Packed<'UserDetailed'> : Packed<'UserLite'>;
type IsMeAndIsUserDetailed<ExpectsMe extends boolean | null, Detailed extends boolean> =
@ -27,7 +30,7 @@ const ajv = new Ajv();
const localUsernameSchema = { type: 'string', pattern: /^\w{1,20}$/.toString().slice(1, -1) } as const;
const passwordSchema = { type: 'string', minLength: 1 } as const;
const nameSchema = { type: 'string', minLength: 1, maxLength: 50 } as const;
const descriptionSchema = { type: 'string', minLength: 1, maxLength: 500 } as const;
const descriptionSchema = { type: 'string', minLength: 1, maxLength: 2048 } as const;
const locationSchema = { type: 'string', minLength: 1, maxLength: 50 } as const;
const birthdaySchema = { type: 'string', pattern: /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.toString().slice(1, -1) } as const;
@ -309,17 +312,15 @@ export const UserRepository = db.getRepository(User).extend({
isModerator: user.isModerator || falsy,
isBot: user.isBot || falsy,
isCat: user.isCat || falsy,
instance: user.host ? userInstanceCache.fetch(user.host,
() => Instances.findOneBy({ host: user.host! }),
v => v != null,
).then(instance => instance ? {
instance: !user.host ? undefined : userInstanceCache.fetch(user.host)
.then(instance => !instance ? undefined : {
name: instance.name,
softwareName: instance.softwareName,
softwareVersion: instance.softwareVersion,
iconUrl: instance.iconUrl,
faviconUrl: instance.faviconUrl,
themeColor: instance.themeColor,
} : undefined) : undefined,
}),
emojis: populateEmojis(user.emojis, user.host),
onlineStatus: this.getOnlineStatus(user),

View file

@ -6,39 +6,20 @@ import Logger from '@/services/logger.js';
import { Instances } from '@/models/index.js';
import { apRequestChart, federationChart, instanceChart } from '@/services/chart/index.js';
import { fetchInstanceMetadata } from '@/services/fetch-instance-metadata.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { toPuny } from '@/misc/convert-host.js';
import { Cache } from '@/misc/cache.js';
import { Instance } from '@/models/entities/instance.js';
import { StatusError } from '@/misc/fetch.js';
import { shouldSkipInstance } from '@/misc/skipped-instances.js';
import { DeliverJobData } from '@/queue/types.js';
import { LessThan } from 'typeorm';
import { DAY } from '@/const.js';
const logger = new Logger('deliver');
let latest: string | null = null;
const deadThreshold = 30 * DAY;
export default async (job: Bull.Job<DeliverJobData>) => {
const { host } = new URL(job.data.to);
const puny = toPuny(host);
// ブロックしてたら中断
const meta = await fetchMeta();
if (meta.blockedHosts.includes(puny)) {
return 'skip (blocked)';
}
const deadTime = new Date(Date.now() - deadThreshold);
const isSuspendedOrDead = await Instances.countBy([
{ host: puny, isSuspended: true },
{ host: puny, lastCommunicatedAt: LessThan(deadTime) },
]);
if (isSuspendedOrDead) {
return 'skip (suspended or dead)';
}
if (await shouldSkipInstance(puny)) return 'skip';
try {
if (latest !== (latest = JSON.stringify(job.data.content, null, 2))) {
@ -81,8 +62,8 @@ export default async (job: Bull.Job<DeliverJobData>) => {
if (res instanceof StatusError) {
// 4xx
if (res.isClientError) {
// HTTPステータスコード4xxはクライアントエラーであり、それはつまり
// 何回再送しても成功することはないということなのでエラーにはしないでおく
// A client error means that something is wrong with the request we are making,
// which means that retrying it makes no sense.
return `${res.statusCode} ${res.statusMessage}`;
}

View file

@ -1,6 +1,6 @@
import Bull from 'bull';
import { In, LessThan } from 'typeorm';
import { AttestationChallenges, Mutings, Signins } from '@/models/index.js';
import { AttestationChallenges, Mutings, PasswordResetRequests, Signins } from '@/models/index.js';
import { publishUserEvent } from '@/services/stream.js';
import { MINUTE, DAY } from '@/const.js';
import { queueLogger } from '@/queue/logger.js';
@ -35,6 +35,11 @@ export async function checkExpired(job: Bull.Job<Record<string, unknown>>, done:
createdAt: LessThan(new Date(new Date().getTime() - 5 * MINUTE)),
});
await PasswordResetRequests.delete({
// this timing should be the same as in @/server/api/endpoints/reset-password.ts
createdAt: LessThan(new Date(new Date().getTime() - 30 * MINUTE)),
});
logger.succ('Deleted expired mutes, signins and attestation challenges.');
done();

View file

@ -10,8 +10,14 @@ import { uriPersonCache, userByIdCache } from '@/services/user-cache.js';
import { IObject, getApId } from './type.js';
import { resolvePerson } from './models/person.js';
const publicKeyCache = new Cache<UserPublickey | null>(Infinity);
const publicKeyByUserIdCache = new Cache<UserPublickey | null>(Infinity);
const publicKeyCache = new Cache<UserPublickey>(
Infinity,
(keyId) => UserPublickeys.findOneBy({ keyId }).then(x => x ?? undefined),
);
const publicKeyByUserIdCache = new Cache<UserPublickey>(
Infinity,
(userId) => UserPublickeys.findOneBy({ userId }).then(x => x ?? undefined),
);
export type UriParseResult = {
/** wether the URI was generated by us */
@ -99,13 +105,9 @@ export default class DbResolver {
if (parsed.local) {
if (parsed.type !== 'users') return null;
return await userByIdCache.fetchMaybe(parsed.id, () => Users.findOneBy({
id: parsed.id,
}).then(x => x ?? undefined)) ?? null;
return await userByIdCache.fetch(parsed.id) ?? null;
} else {
return await uriPersonCache.fetch(parsed.uri, () => Users.findOneBy({
uri: parsed.uri,
}));
return await uriPersonCache.fetch(parsed.uri) ?? null;
}
}
@ -116,20 +118,12 @@ export default class DbResolver {
user: CacheableRemoteUser;
key: UserPublickey;
} | null> {
const key = await publicKeyCache.fetch(keyId, async () => {
const key = await UserPublickeys.findOneBy({
keyId,
});
if (key == null) return null;
return key;
}, key => key != null);
const key = await publicKeyCache.fetch(keyId);
if (key == null) return null;
return {
user: await userByIdCache.fetch(key.userId, () => Users.findOneByOrFail({ id: key.userId })) as CacheableRemoteUser,
user: await userByIdCache.fetch(key.userId) as CacheableRemoteUser,
key,
};
}
@ -145,7 +139,7 @@ export default class DbResolver {
if (user == null) return null;
const key = await publicKeyByUserIdCache.fetch(user.id, () => UserPublickeys.findOneBy({ userId: user.id }), v => v != null);
const key = await publicKeyByUserIdCache.fetch(user.id);
return {
user,

View file

@ -2,6 +2,7 @@ import { IsNull, Not } from 'typeorm';
import { ILocalUser, IRemoteUser, User } from '@/models/entities/user.js';
import { Users, Followings } from '@/models/index.js';
import { deliver } from '@/queue/index.js';
import { skippedInstances } from '@/misc/skipped-instances.js';
//#region types
interface IRecipe {
@ -118,26 +119,18 @@ export default class DeliverManager {
if (this.recipes.some(r => isFollowers(r))) {
// followers deliver
// TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう
// ただ、sharedInboxがnullなリモートユーザーも稀におり、その対応ができなさそう
const followers = await Followings.find({
where: {
followeeId: this.actor.id,
followerHost: Not(IsNull()),
},
select: {
followerSharedInbox: true,
followerInbox: true,
},
}) as {
followerSharedInbox: string | null;
followerInbox: string;
}[];
const followers = await Followings.createQueryBuilder('followings')
// return either the shared inbox (if available) or the individual inbox
.select('COALESCE(followings.followerSharedInbox, followings.followerInbox)', 'inbox')
// so we don't have to make our inboxes Set work as hard
.distinct(true)
// ...for the specific actors followers
.where('followings.followeeId = :actorId', { actorId: this.actor.id })
// don't deliver to ourselves
.andWhere('followings.followerHost IS NOT NULL')
.getRawMany();
for (const following of followers) {
const inbox = following.followerSharedInbox || following.followerInbox;
inboxes.add(inbox);
}
followers.forEach(({ inbox }) => inboxes.add(inbox));
}
this.recipes.filter((recipe): recipe is IDirectRecipe =>
@ -150,8 +143,19 @@ export default class DeliverManager {
)
.forEach(recipe => inboxes.add(recipe.to.inbox!));
const instancesToSkip = await skippedInstances(
// get (unique) list of hosts
Array.from(new Set(
Array.from(inboxes)
.map(inbox => new URL(inbox).host)
))
);
// deliver
for (const inbox of inboxes) {
// skip instances as indicated
if (instancesToSkip.includes(new URL(inbox).host)) continue;
deliver(this.actor, this.activity, inbox);
}
}

View file

@ -1,5 +1,5 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import create from '@/services/note/reaction/create.js';
import { createReaction } from '@/services/note/reaction/create.js';
import { ILike, getApId } from '../type.js';
import { fetchNote, extractEmojis } from '../models/note.js';
@ -11,7 +11,7 @@ export default async (actor: CacheableRemoteUser, activity: ILike) => {
await extractEmojis(activity.tag || [], actor.host).catch(() => null);
return await create(actor, note, activity._misskey_reaction || activity.content || activity.name).catch(e => {
return await createReaction(actor, note, activity._misskey_reaction || activity.content || activity.name).catch(e => {
if (e.id === '51c42bb4-931a-456b-bff7-e5a8a70dd298') {
return 'skip: already reacted';
} else {

View file

@ -1,5 +1,5 @@
import { CacheableRemoteUser } from '@/models/entities/user.js';
import deleteReaction from '@/services/note/reaction/delete.js';
import { deleteReaction } from '@/services/note/reaction/delete.js';
import { ILike, getApId } from '@/remote/activitypub/type.js';
import { fetchNote } from '@/remote/activitypub/models/note.js';

View file

@ -4,7 +4,7 @@ import config from '@/config/index.js';
import post from '@/services/note/create.js';
import { CacheableRemoteUser } from '@/models/entities/user.js';
import { unique, toArray, toSingle } from '@/prelude/array.js';
import vote from '@/services/note/polls/vote.js';
import { vote } from '@/services/note/polls/vote.js';
import { DriveFile } from '@/models/entities/drive-file.js';
import { deliverQuestionUpdate } from '@/services/note/polls/update.js';
import { extractDbHost, toPuny } from '@/misc/convert-host.js';

View file

@ -34,7 +34,7 @@ export default async (user: { id: User['id'] }, url: string, object: any) => {
* @param user http-signature user
* @param url URL to fetch
*/
export async function signedGet(url: string, user: { id: User['id'] }) {
export async function signedGet(url: string, user: { id: User['id'] }): Promise<any> {
const keypair = await getUserKeypair(user.id);
const req = createSignedGet({

View file

@ -23,8 +23,6 @@ import Featured from './activitypub/featured.js';
// Init router
const router = new Router();
//#region Routing
function inbox(ctx: Router.RouterContext) {
let signature;
@ -45,6 +43,8 @@ const LD_JSON = 'application/ld+json; profile="https://www.w3.org/ns/activitystr
function isActivityPubReq(ctx: Router.RouterContext) {
ctx.response.vary('Accept');
// if no accept header is supplied, koa returns the 1st, so html is used as a dummy
// i.e. activitypub requests must be explicit
const accepted = ctx.accepts('html', ACTIVITY_JSON, LD_JSON);
return typeof accepted === 'string' && !accepted.match(/html/);
}
@ -77,7 +77,7 @@ router.get('/notes/:note', async (ctx, next) => {
return;
}
// リモートだったらリダイレクト
// redirect if remote
if (note.userHost != null) {
if (note.uri == null || isSelfHost(note.userHost)) {
ctx.status = 500;
@ -94,6 +94,15 @@ router.get('/notes/:note', async (ctx, next) => {
// note activity
router.get('/notes/:note/activity', async ctx => {
if (!isActivityPubReq(ctx)) {
/*
Redirect to the human readable page. in this case using next is not possible,
since there is no human readable page explicitly for the activity.
*/
ctx.redirect(`/notes/${ctx.params.note}`);
return;
}
const note = await Notes.findOneBy({
id: ctx.params.note,
userHost: IsNull(),
@ -185,7 +194,6 @@ router.get('/@:user', async (ctx, next) => {
await userInfo(ctx, user);
});
//#endregion
// emoji
router.get('/emojis/:emoji', async ctx => {

View file

@ -5,59 +5,51 @@ import authenticate, { AuthenticationError } from './authenticate.js';
import call from './call.js';
import { ApiError } from './error.js';
export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise<void>((res) => {
export async function handler(endpoint: IEndpoint, ctx: Koa.Context): Promise<void> {
const body = ctx.is('multipart/form-data')
? (ctx.request as any).body
: ctx.method === 'GET'
? ctx.query
: ctx.request.body;
const reply = (x?: any, y?: ApiError) => {
if (x == null) {
ctx.status = 204;
} else if (typeof x === 'number' && y) {
ctx.status = x;
const error = (e: ApiError): void => {
ctx.status = e.httpStatusCode;
if (e.httpStatusCode === 401) {
ctx.response.set('WWW-Authenticate', 'Bearer');
}
ctx.body = {
error: {
message: y!.message,
code: y!.code,
id: y!.id,
kind: y!.kind,
...(y!.info ? { info: y!.info } : {}),
message: e!.message,
code: e!.code,
...(e!.info ? { info: e!.info } : {}),
endpoint: endpoint.name,
},
};
} else {
// 文字列を返す場合は、JSON.stringify通さないとJSONと認識されない
ctx.body = typeof x === 'string' ? JSON.stringify(x) : x;
}
res();
};
// Authentication
// for GET requests, do not even pass on the body parameter as it is considered unsafe
authenticate(ctx.headers.authorization, ctx.method === 'GET' ? null : body['i']).then(([user, app]) => {
await authenticate(ctx.headers.authorization, ctx.method === 'GET' ? null : body['i']).then(async ([user, app]) => {
// API invoking
call(endpoint.name, user, app, body, ctx).then((res: any) => {
await call(endpoint.name, user, app, body, ctx).then((res: any) => {
if (ctx.method === 'GET' && endpoint.meta.cacheSec && !body['i'] && !user) {
ctx.set('Cache-Control', `public, max-age=${endpoint.meta.cacheSec}`);
}
reply(res);
if (res == null) {
ctx.status = 204;
} else {
ctx.status = 200;
// If a string is returned, it must be passed through JSON.stringify to be recognized as JSON.
ctx.body = typeof res === 'string' ? JSON.stringify(res) : res;
}
}).catch((e: ApiError) => {
reply(e.httpStatusCode ? e.httpStatusCode : e.kind === 'client' ? 400 : 500, e);
error(e);
});
}).catch(e => {
if (e instanceof AuthenticationError) {
ctx.response.status = 403;
ctx.response.set('WWW-Authenticate', 'Bearer');
ctx.response.body = {
message: 'Authentication failed: ' + e.message,
code: 'AUTHENTICATION_FAILED',
id: 'b0a7f5f8-dc2f-4171-b91f-de88ad238e14',
kind: 'client',
};
res();
error(new ApiError('AUTHENTICATION_FAILED', e.message));
} else {
reply(500, new ApiError());
error(new ApiError());
}
});
});
}

View file

@ -3,10 +3,13 @@ import { Users, AccessTokens, Apps } from '@/models/index.js';
import { AccessToken } from '@/models/entities/access-token.js';
import { Cache } from '@/misc/cache.js';
import { App } from '@/models/entities/app.js';
import { localUserByIdCache, localUserByNativeTokenCache } from '@/services/user-cache.js';
import { userByIdCache, localUserByNativeTokenCache } from '@/services/user-cache.js';
import isNativeToken from './common/is-native-token.js';
const appCache = new Cache<App>(Infinity);
const appCache = new Cache<App>(
Infinity,
(id) => Apps.findOneByOrFail({ id }),
);
export class AuthenticationError extends Error {
constructor(message: string) {
@ -15,8 +18,8 @@ export class AuthenticationError extends Error {
}
}
export default async (authorization: string | null | undefined, bodyToken: string | null): Promise<[CacheableLocalUser | null | undefined, AccessToken | null | undefined]> => {
let token: string | null = null;
export default async (authorization: string | null | undefined, bodyToken: string | null | undefined): Promise<[CacheableLocalUser | null | undefined, AccessToken | null | undefined]> => {
let maybeToken: string | null = null;
// check if there is an authorization header set
if (authorization != null) {
@ -27,19 +30,19 @@ export default async (authorization: string | null | undefined, bodyToken: strin
// check if OAuth 2.0 Bearer tokens are being used
// Authorization schemes are case insensitive
if (authorization.substring(0, 7).toLowerCase() === 'bearer ') {
token = authorization.substring(7);
maybeToken = authorization.substring(7);
} else {
throw new AuthenticationError('unsupported authentication scheme');
}
} else if (bodyToken != null) {
token = bodyToken;
maybeToken = bodyToken;
} else {
return [null, null];
}
const token: string = maybeToken;
if (isNativeToken(token)) {
const user = await localUserByNativeTokenCache.fetch(token,
() => Users.findOneBy({ token }) as Promise<ILocalUser | null>);
const user = await localUserByNativeTokenCache.fetch(token);
if (user == null) {
throw new AuthenticationError('unknown token');
@ -63,14 +66,13 @@ export default async (authorization: string | null | undefined, bodyToken: strin
lastUsedAt: new Date(),
});
const user = await localUserByIdCache.fetch(accessToken.userId,
() => Users.findOneBy({
id: accessToken.userId,
}) as Promise<ILocalUser>);
const user = await userByIdCache.fetch(accessToken.userId);
// can't authorize remote users
if (!Users.isLocalUser(user)) return [null, null];
if (accessToken.appId) {
const app = await appCache.fetch(accessToken.appId,
() => Apps.findOneByOrFail({ id: accessToken.appId! }));
const app = await appCache.fetch(accessToken.appId);
return [user, {
id: accessToken.id,

View file

@ -8,29 +8,16 @@ import endpoints, { IEndpointMeta } from './endpoints.js';
import { ApiError } from './error.js';
import { apiLogger } from './logger.js';
const accessDenied = {
message: 'Access denied.',
code: 'ACCESS_DENIED',
id: '56f35758-7dd5-468b-8439-5d6fb8ec9b8e',
};
export default async (endpoint: string, user: CacheableLocalUser | null | undefined, token: AccessToken | null | undefined, data: any, ctx?: Koa.Context) => {
const isSecure = user != null && token == null;
const isModerator = user != null && (user.isModerator || user.isAdmin);
const ep = endpoints.find(e => e.name === endpoint);
if (ep == null) {
throw new ApiError({
message: 'No such endpoint.',
code: 'NO_SUCH_ENDPOINT',
id: 'f8080b67-5f9c-4eb7-8c18-7f1eeae8f709',
httpStatusCode: 404,
});
}
if (ep == null) throw new ApiError('NO_SUCH_ENDPOINT');
if (ep.meta.secure && !isSecure) {
throw new ApiError(accessDenied);
throw new ApiError('ACCESS_DENIED', 'This operation can only be performed with a native token.');
}
if (ep.meta.limit && !isModerator) {
@ -49,48 +36,29 @@ export default async (endpoint: string, user: CacheableLocalUser | null | undefi
}
// Rate limit
await limiter(limit as IEndpointMeta['limit'] & { key: NonNullable<string> }, limitActor).catch(e => {
throw new ApiError({
message: 'Rate limit exceeded. Please try again later.',
code: 'RATE_LIMIT_EXCEEDED',
id: 'd5826d14-3982-4d2e-8011-b9e9f02499ef',
httpStatusCode: 429,
});
await limiter(limit as IEndpointMeta['limit'] & { key: NonNullable<string> }, limitActor).catch(() => {
throw new ApiError('RATE_LIMIT_EXCEEDED');
});
}
if (ep.meta.requireCredential && user == null) {
throw new ApiError({
message: 'Credential required.',
code: 'CREDENTIAL_REQUIRED',
id: '1384574d-a912-4b81-8601-c7b1c4085df1',
httpStatusCode: 401,
});
throw new ApiError('AUTHENTICATION_REQUIRED');
}
if (ep.meta.requireCredential && user!.isSuspended) {
throw new ApiError({
message: 'Your account has been suspended.',
code: 'YOUR_ACCOUNT_SUSPENDED',
id: 'a8c724b3-6e9c-4b46-b1a8-bc3ed6258370',
httpStatusCode: 403,
});
throw new ApiError('SUSPENDED');
}
if (ep.meta.requireAdmin && !user!.isAdmin) {
throw new ApiError(accessDenied, { reason: 'You are not the admin.' });
throw new ApiError('ACCESS_DENIED', 'This operation requires administrator privileges.');
}
if (ep.meta.requireModerator && !isModerator) {
throw new ApiError(accessDenied, { reason: 'You are not a moderator.' });
throw new ApiError('ACCESS_DENIED', 'This operation requires moderator privileges.');
}
if (token && ep.meta.kind && !token.permission.some(p => p === ep.meta.kind)) {
throw new ApiError({
message: 'Your app does not have the necessary permissions to use this endpoint.',
code: 'PERMISSION_DENIED',
id: '1370e5b7-d4eb-4566-bb1d-7748ee6a1838',
});
throw new ApiError('ACCESS_DENIED', 'This operation requires privileges which this token does not grant.');
}
// Cast non JSON input
@ -101,11 +69,7 @@ export default async (endpoint: string, user: CacheableLocalUser | null | undefi
try {
data[k] = JSON.parse(data[k]);
} catch (e) {
throw new ApiError({
message: 'Invalid param.',
code: 'INVALID_PARAM',
id: '0b5f1631-7c1a-41a6-b399-cce335f34d85',
}, {
throw new ApiError('INVALID_PARAM', {
param: k,
reason: `cannot cast to ${param.type}`,
});
@ -129,7 +93,7 @@ export default async (endpoint: string, user: CacheableLocalUser | null | undefi
stack: e.stack,
},
});
throw new ApiError(null, {
throw new ApiError('INTERNAL_ERROR', {
e: {
message: e.message,
code: e.name,

View file

@ -24,25 +24,13 @@ export async function signup(opts: {
// Validate username
if (!Users.validateLocalUsername(username)) {
throw new ApiError({
message: 'This username is invalid.',
code: 'INVALID_USERNAME',
id: 'ece89f3c-d845-4d9a-850b-1735285e8cd4',
kind: 'client',
httpStatusCode: 400,
});
throw new ApiError('INVALID_USERNAME');
}
if (password != null && passwordHash == null) {
// Validate password
if (!Users.validatePassword(password)) {
throw new ApiError({
message: 'This password is invalid.',
code: 'INVALID_PASSWORD',
id: 'a941905b-fe7b-43e2-8ecd-50ad3a2287ab',
kind: 'client',
httpStatusCode: 400,
});
throw new ApiError('INVALID_PASSWORD');
}
// Generate hash of password
@ -53,22 +41,14 @@ export async function signup(opts: {
// Generate secret
const secret = generateUserToken();
const duplicateUsernameError = {
message: 'This username is not available.',
code: 'USED_USERNAME',
id: '7ddd595e-6860-4593-93c5-9fdbcb80cd81',
kind: 'client',
httpStatusCode: 409,
};
// Check username duplication
if (await Users.findOneBy({ usernameLower: username.toLowerCase(), host: IsNull() })) {
throw new ApiError(duplicateUsernameError);
throw new ApiError('USED_USERNAME');
}
// Check deleted username duplication
if (await UsedUsernames.findOneBy({ username: username.toLowerCase() })) {
throw new ApiError(duplicateUsernameError);
throw new ApiError('USED_USERNAME');
}
const keyPair = await new Promise<string[]>((res, rej) =>
@ -97,7 +77,7 @@ export async function signup(opts: {
host: IsNull(),
});
if (exist) throw new ApiError(duplicateUsernameError);
if (exist) throw new ApiError('USED_USERNAME');
account = await transactionalEntityManager.save(new User({
id: genId(),

View file

@ -28,22 +28,16 @@ export default function <T extends IEndpointMeta, Ps extends Schema>(meta: T, pa
fs.unlink(file.path, () => {});
}
if (meta.requireFile && file == null) return Promise.reject(new ApiError({
message: 'File required.',
code: 'FILE_REQUIRED',
id: '4267801e-70d1-416a-b011-4ee502885d8b',
}));
if (meta.requireFile && file == null) {
return Promise.reject(new ApiError('FILE_REQUIRED'));
}
const valid = validate(params);
if (!valid) {
if (file) cleanup();
const errors = validate.errors!;
const err = new ApiError({
message: 'Invalid param.',
code: 'INVALID_PARAM',
id: '3d81ceae-475f-4600-b2a8-2bc116157532',
}, {
const err = new ApiError('INVALID_PARAM', {
param: errors[0].schemaPath,
reason: errors[0].message,
});

View file

@ -1,4 +1,5 @@
import { Schema } from '@/misc/schema.js';
import { errors } from './error.js';
import * as ep___admin_meta from './endpoints/admin/meta.js';
import * as ep___admin_abuseUserReports from './endpoints/admin/abuse-user-reports.js';
@ -270,14 +271,12 @@ import * as ep___serverInfo from './endpoints/server-info.js';
import * as ep___stats from './endpoints/stats.js';
import * as ep___sw_register from './endpoints/sw/register.js';
import * as ep___sw_unregister from './endpoints/sw/unregister.js';
import * as ep___test from './endpoints/test.js';
import * as ep___username_available from './endpoints/username/available.js';
import * as ep___users from './endpoints/users.js';
import * as ep___users_clips from './endpoints/users/clips.js';
import * as ep___users_followers from './endpoints/users/followers.js';
import * as ep___users_following from './endpoints/users/following.js';
import * as ep___users_gallery_posts from './endpoints/users/gallery/posts.js';
import * as ep___users_getFrequentlyRepliedUsers from './endpoints/users/get-frequently-replied-users.js';
import * as ep___users_groups_create from './endpoints/users/groups/create.js';
import * as ep___users_groups_delete from './endpoints/users/groups/delete.js';
import * as ep___users_groups_invitations_accept from './endpoints/users/groups/invitations/accept.js';
@ -580,14 +579,12 @@ const eps = [
['stats', ep___stats],
['sw/register', ep___sw_register],
['sw/unregister', ep___sw_unregister],
['test', ep___test],
['username/available', ep___username_available],
['users', ep___users],
['users/clips', ep___users_clips],
['users/followers', ep___users_followers],
['users/following', ep___users_following],
['users/gallery/posts', ep___users_gallery_posts],
['users/get-frequently-replied-users', ep___users_getFrequentlyRepliedUsers],
['users/groups/create', ep___users_groups_create],
['users/groups/delete', ep___users_groups_delete],
['users/groups/invitations/accept', ep___users_groups_invitations_accept],
@ -625,13 +622,7 @@ export interface IEndpointMeta {
readonly tags?: ReadonlyArray<string>;
readonly errors?: {
readonly [key: string]: {
readonly message: string;
readonly code: string;
readonly id: string;
};
};
readonly errors?: ReadonlyArray<keyof typeof errors>;
readonly res?: Schema;

View file

@ -8,13 +8,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
noSuchAnnouncement: {
message: 'No such announcement.',
code: 'NO_SUCH_ANNOUNCEMENT',
id: 'ecad8040-a276-4e85-bda9-015a708d291e',
},
},
errors: ['NO_SUCH_ANNOUNCEMENT'],
} as const;
export const paramDef = {
@ -29,7 +23,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, me) => {
const announcement = await Announcements.findOneBy({ id: ps.id });
if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement);
if (announcement == null) throw new ApiError('NO_SUCH_ANNOUNCEMENT');
await Announcements.delete(announcement.id);
});

View file

@ -8,13 +8,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
noSuchAnnouncement: {
message: 'No such announcement.',
code: 'NO_SUCH_ANNOUNCEMENT',
id: 'd3aae5a7-6372-4cb4-b61c-f511ffc2d7cc',
},
},
errors: ['NO_SUCH_ANNOUNCEMENT'],
} as const;
export const paramDef = {
@ -32,7 +26,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, me) => {
const announcement = await Announcements.findOneBy({ id: ps.id });
if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement);
if (announcement == null) throw new ApiError('NO_SUCH_ANNOUNCEMENT');
await Announcements.update(announcement.id, {
updatedAt: new Date(),

View file

@ -8,13 +8,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: 'caf3ca38-c6e5-472e-a30c-b05377dcc240',
},
},
errors: ['NO_SUCH_FILE'],
res: {
type: 'object',
@ -180,9 +174,7 @@ export default define(meta, paramDef, async (ps, me) => {
}],
});
if (file == null) {
throw new ApiError(meta.errors.noSuchFile);
}
if (file == null) throw new ApiError('NO_SUCH_FILE');
return file;
});

View file

@ -13,13 +13,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
noSuchFile: {
message: 'No such file.',
code: 'MO_SUCH_FILE',
id: 'fc46b5a4-6b92-4c33-ac66-b806659bb5cf',
},
},
errors: ['NO_SUCH_FILE'],
} as const;
export const paramDef = {
@ -34,7 +28,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, me) => {
const file = await DriveFiles.findOneBy({ id: ps.fileId });
if (file == null) throw new ApiError(meta.errors.noSuchFile);
if (file == null) throw new ApiError('NO_SUCH_FILE');
const name = file.name.split('.')[0].match(/^[a-z0-9_]+$/) ? file.name.split('.')[0] : `_${rndstr('a-z0-9', 8)}_`;

View file

@ -13,13 +13,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
noSuchEmoji: {
message: 'No such emoji.',
code: 'NO_SUCH_EMOJI',
id: 'e2785b66-dca3-4087-9cac-b93c541cc425',
},
},
errors: ['NO_SUCH_EMOJI', 'INTERNAL_ERROR'],
res: {
type: 'object',
@ -46,9 +40,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, me) => {
const emoji = await Emojis.findOneBy({ id: ps.emojiId });
if (emoji == null) {
throw new ApiError(meta.errors.noSuchEmoji);
}
if (emoji == null) throw new ApiError('NO_SUCH_EMOJI');
let driveFile: DriveFile;
@ -56,7 +48,7 @@ export default define(meta, paramDef, async (ps, me) => {
// Create file
driveFile = await uploadFromUrl({ url: emoji.originalUrl, user: null, force: true });
} catch (e) {
throw new ApiError();
throw new ApiError('INTERNAL_ERROR', e);
}
const copied = await Emojis.insert({

View file

@ -10,13 +10,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
noSuchEmoji: {
message: 'No such emoji.',
code: 'NO_SUCH_EMOJI',
id: 'be83669b-773a-44b7-b1f8-e5e5170ac3c2',
},
},
errors: ['NO_SUCH_EMOJI'],
} as const;
export const paramDef = {
@ -31,7 +25,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, me) => {
const emoji = await Emojis.findOneBy({ id: ps.id });
if (emoji == null) throw new ApiError(meta.errors.noSuchEmoji);
if (emoji == null) throw new ApiError('NO_SUCH_EMOJI');
await Emojis.delete(emoji.id);

View file

@ -9,13 +9,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
noSuchEmoji: {
message: 'No such emoji.',
code: 'NO_SUCH_EMOJI',
id: '684dec9d-a8c2-4364-9aa8-456c49cb1dc8',
},
},
errors: ['NO_SUCH_EMOJI'],
} as const;
export const paramDef = {
@ -39,7 +33,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps) => {
const emoji = await Emojis.findOneBy({ id: ps.id });
if (emoji == null) throw new ApiError(meta.errors.noSuchEmoji);
if (emoji == null) throw new ApiError('NO_SUCH_EMOJI');
await Emojis.update(emoji.id, {
updatedAt: new Date(),

View file

@ -1,6 +1,5 @@
import config from '@/config/index.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { MAX_NOTE_TEXT_LENGTH } from '@/const.js';
import define from '../../define.js';
export const meta = {
@ -310,7 +309,7 @@ export default define(meta, paramDef, async (ps, me) => {
iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため
maxNoteTextLength: config.maxNoteTextLength,
defaultLightTheme: instance.defaultLightTheme,
defaultDarkTheme: instance.defaultDarkTheme,
enableEmail: instance.enableEmail,

View file

@ -9,13 +9,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
errors: {
invalidUrl: {
message: 'Invalid URL',
code: 'INVALID_URL',
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c',
},
},
errors: ['INVALID_URL'],
res: {
type: 'object',
@ -58,8 +52,8 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
try {
if (new URL(ps.inbox).protocol !== 'https:') throw new Error('https only');
} catch {
throw new ApiError(meta.errors.invalidUrl);
} catch (e) {
throw new ApiError('INVALID_URL', e);
}
return await addRelay(ps.inbox);

View file

@ -1,6 +1,5 @@
import { Meta } from '@/models/entities/meta.js';
import { insertModerationLog } from '@/services/insert-moderation-log.js';
import { db } from '@/db/postgre.js';
import { fetchMeta, setMeta } from '@/misc/fetch-meta.js';
import define from '../../define.js';
export const meta = {
@ -375,20 +374,10 @@ export default define(meta, paramDef, async (ps, me) => {
set.deeplIsPro = ps.deeplIsPro;
}
await db.transaction(async transactionalEntityManager => {
const metas = await transactionalEntityManager.find(Meta, {
order: {
id: 'DESC',
},
});
const meta = metas[0];
if (meta) {
await transactionalEntityManager.update(Meta, meta.id, set);
} else {
await transactionalEntityManager.save(Meta, set);
}
const meta = await fetchMeta();
await setMeta({
...meta,
...set,
});
insertModerationLog(me, 'updateMeta');

View file

@ -11,19 +11,7 @@ export const meta = {
kind: 'write:account',
errors: {
noSuchUserList: {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
id: '95063e93-a283-4b8b-9aa5-bcdb8df69a7f',
},
noSuchUserGroup: {
message: 'No such user group.',
code: 'NO_SUCH_USER_GROUP',
id: 'aa3c0b9a-8cae-47c0-92ac-202ce5906682',
},
},
errors: ['NO_SUCH_USER_LIST', 'NO_SUCH_GROUP'],
res: {
type: 'object',
@ -71,18 +59,14 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (userList == null) {
throw new ApiError(meta.errors.noSuchUserList);
}
if (userList == null) throw new ApiError('NO_SUCH_USER_LIST');
} else if (ps.src === 'group' && ps.userGroupId) {
userGroupJoining = await UserGroupJoinings.findOneBy({
userGroupId: ps.userGroupId,
userId: user.id,
});
if (userGroupJoining == null) {
throw new ApiError(meta.errors.noSuchUserGroup);
}
if (userGroupJoining == null) throw new ApiError('NO_SUCH_GROUP');
}
const antenna = await Antennas.insert({

View file

@ -10,13 +10,7 @@ export const meta = {
kind: 'write:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: 'b34dcf9d-348f-44bb-99d0-6c9314cfe2df',
},
},
errors: ['NO_SUCH_ANTENNA'],
} as const;
export const paramDef = {
@ -34,9 +28,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (antenna == null) {
throw new ApiError(meta.errors.noSuchAntenna);
}
if (antenna == null) throw new ApiError('NO_SUCH_ANTENNA');
await Antennas.delete(antenna.id);

View file

@ -1,4 +1,4 @@
import readNote from '@/services/note/read.js';
import { readNote } from '@/services/note/read.js';
import { Antennas, Notes, AntennaNotes } from '@/models/index.js';
import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { generateVisibilityQuery } from '../../common/generate-visibility-query.js';
@ -14,13 +14,7 @@ export const meta = {
kind: 'read:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: '850926e0-fd3b-49b6-b69a-b28a5dbd82fe',
},
},
errors: ['NO_SUCH_ANTENNA'],
res: {
type: 'array',
@ -53,9 +47,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (antenna == null) {
throw new ApiError(meta.errors.noSuchAntenna);
}
if (antenna == null) throw new ApiError('NO_SUCH_ANTENNA');
const query = makePaginationQuery(Notes.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)

View file

@ -9,13 +9,7 @@ export const meta = {
kind: 'read:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: 'c06569fb-b025-4f23-b22d-1fcd20d2816b',
},
},
errors: ['NO_SUCH_ANTENNA'],
res: {
type: 'object',
@ -40,9 +34,7 @@ export default define(meta, paramDef, async (ps, me) => {
userId: me.id,
});
if (antenna == null) {
throw new ApiError(meta.errors.noSuchAntenna);
}
if (antenna == null) throw new ApiError('NO_SUCH_ANTENNA');
return await Antennas.pack(antenna);
});

View file

@ -10,25 +10,7 @@ export const meta = {
kind: 'write:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: '10c673ac-8852-48eb-aa1f-f5b67f069290',
},
noSuchUserList: {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
id: '1c6b35c9-943e-48c2-81e4-2844989407f7',
},
noSuchUserGroup: {
message: 'No such user group.',
code: 'NO_SUCH_USER_GROUP',
id: '109ed789-b6eb-456e-b8a9-6059d567d385',
},
},
errors: ['NO_SUCH_ANTENNA', 'NO_SUCH_USER_LIST', 'NO_SUCH_GROUP'],
res: {
type: 'object',
@ -74,9 +56,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (antenna == null) {
throw new ApiError(meta.errors.noSuchAntenna);
}
if (antenna == null) throw new ApiError('NO_SUCH_ANTENNA');
let userList;
let userGroupJoining;
@ -87,18 +67,14 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (userList == null) {
throw new ApiError(meta.errors.noSuchUserList);
}
if (userList == null) throw new ApiError('NO_SUCH_USER_LIST');
} else if (ps.src === 'group' && ps.userGroupId) {
userGroupJoining = await UserGroupJoinings.findOneBy({
userGroupId: ps.userGroupId,
userId: user.id,
});
if (userGroupJoining == null) {
throw new ApiError(meta.errors.noSuchUserGroup);
}
if (userGroupJoining == null) throw new ApiError('NO_SUCH_GROUP');
}
await Antennas.update(antenna.id, {

View file

@ -12,9 +12,6 @@ export const meta = {
max: 30,
},
errors: {
},
res: {
type: 'object',
optional: false, nullable: false,

View file

@ -24,13 +24,7 @@ export const meta = {
max: 30,
},
errors: {
noSuchObject: {
message: 'No such object.',
code: 'NO_SUCH_OBJECT',
id: 'dc94d745-1262-4e63-a17d-fecaa57efc82',
},
},
errors: ['NO_SUCH_OBJECT'],
res: {
optional: false, nullable: false,
@ -83,7 +77,7 @@ export default define(meta, paramDef, async (ps, me) => {
if (object) {
return object;
} else {
throw new ApiError(meta.errors.noSuchObject);
throw new ApiError('NO_SUCH_OBJECT');
}
});

View file

@ -2,6 +2,7 @@ import { Apps } from '@/models/index.js';
import { genId } from '@/misc/gen-id.js';
import { unique } from '@/prelude/array.js';
import { secureRndstr } from '@/misc/secure-rndstr.js';
import { kinds } from '@/misc/api-permissions.js';
import define from '../../define.js';
export const meta = {
@ -21,10 +22,14 @@ export const paramDef = {
properties: {
name: { type: 'string' },
description: { type: 'string' },
permission: { type: 'array', uniqueItems: true, items: {
permission: {
type: 'array',
uniqueItems: true,
items: {
type: 'string',
// FIXME: add enum of possible permissions
} },
enum: kinds,
},
},
callbackUrl: { type: 'string', nullable: true },
},
required: ['name', 'description', 'permission'],

View file

@ -5,13 +5,7 @@ import { ApiError } from '../../error.js';
export const meta = {
tags: ['app'],
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: 'dce83913-2dc6-4093-8a7b-71dbb11718a3',
},
},
errors: ['NO_SUCH_APP'],
res: {
type: 'object',
@ -33,14 +27,12 @@ export default define(meta, paramDef, async (ps, user, token) => {
const isSecure = user != null && token == null;
// Lookup app
const ap = await Apps.findOneBy({ id: ps.appId });
const app = await Apps.findOneBy({ id: ps.appId });
if (ap == null) {
throw new ApiError(meta.errors.noSuchApp);
}
if (app == null) throw new ApiError('NO_SUCH_APP');
return await Apps.pack(ap, user, {
return await Apps.pack(app, user, {
detail: true,
includeSecret: isSecure && (ap.userId === user!.id),
includeSecret: isSecure && (app.userId === user!.id),
});
});

View file

@ -12,13 +12,7 @@ export const meta = {
secure: true,
errors: {
noSuchSession: {
message: 'No such session.',
code: 'NO_SUCH_SESSION',
id: '9c72d8de-391a-43c1-9d06-08d29efde8df',
},
},
errors: ['NO_SUCH_SESSION'],
} as const;
export const paramDef = {
@ -35,9 +29,7 @@ export default define(meta, paramDef, async (ps, user) => {
const session = await AuthSessions
.findOneBy({ token: ps.token });
if (session == null) {
throw new ApiError(meta.errors.noSuchSession);
}
if (session == null) throw new ApiError('NO_SUCH_SESSION');
// Generate access token
const accessToken = secureRndstr(32, true);

View file

@ -26,13 +26,7 @@ export const meta = {
},
},
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: '92f93e63-428e-4f2f-a5a4-39e1407fe998',
},
},
errors: ['NO_SUCH_APP'],
} as const;
export const paramDef = {
@ -51,7 +45,7 @@ export default define(meta, paramDef, async (ps) => {
});
if (app == null) {
throw new ApiError(meta.errors.noSuchApp);
throw new ApiError('NO_SUCH_APP');
}
// Generate token

View file

@ -7,13 +7,7 @@ export const meta = {
requireCredential: false,
errors: {
noSuchSession: {
message: 'No such session.',
code: 'NO_SUCH_SESSION',
id: 'bd72c97d-eba7-4adb-a467-f171b8847250',
},
},
errors: ['NO_SUCH_SESSION'],
res: {
type: 'object',
@ -52,9 +46,7 @@ export default define(meta, paramDef, async (ps, user) => {
token: ps.token,
});
if (session == null) {
throw new ApiError(meta.errors.noSuchSession);
}
if (session == null) throw new ApiError('NO_SUCH_SESSION');
return await AuthSessions.pack(session, user);
});

View file

@ -24,25 +24,7 @@ export const meta = {
},
},
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: 'fcab192a-2c5a-43b7-8ad8-9b7054d8d40d',
},
noSuchSession: {
message: 'No such session.',
code: 'NO_SUCH_SESSION',
id: '5b5a1503-8bc8-4bd0-8054-dc189e8cdcb3',
},
pendingSession: {
message: 'This session is not completed yet.',
code: 'PENDING_SESSION',
id: '8c8a4145-02cc-4cca-8e66-29ba60445a8e',
},
},
errors: ['NO_SUCH_APP', 'NO_SUCH_SESSION', 'PENDING_SESSION'],
} as const;
export const paramDef = {
@ -61,9 +43,7 @@ export default define(meta, paramDef, async (ps) => {
secret: ps.appSecret,
});
if (app == null) {
throw new ApiError(meta.errors.noSuchApp);
}
if (app == null) throw new ApiError('NO_SUCH_APP');
// Fetch token
const session = await AuthSessions.findOneBy({
@ -71,13 +51,9 @@ export default define(meta, paramDef, async (ps) => {
appId: app.id,
});
if (session == null) {
throw new ApiError(meta.errors.noSuchSession);
}
if (session == null) throw new ApiError('NO_SUCH_SESSION');
if (session.userId == null) {
throw new ApiError(meta.errors.pendingSession);
}
if (session.userId == null) throw new ApiError('PENDING_SESSION');
// Lookup access token
const accessToken = await AccessTokens.findOneByOrFail({

View file

@ -17,25 +17,7 @@ export const meta = {
kind: 'write:blocks',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '7cc4f851-e2f1-4621-9633-ec9e1d00c01e',
},
blockeeIsYourself: {
message: 'Blockee is yourself.',
code: 'BLOCKEE_IS_YOURSELF',
id: '88b19138-f28d-42c0-8499-6a31bbd0fdc6',
},
alreadyBlocking: {
message: 'You are already blocking that user.',
code: 'ALREADY_BLOCKING',
id: '787fed64-acb9-464a-82eb-afbd745b9614',
},
},
errors: ['NO_SUCH_USER', 'BLOCKEE_IS_YOURSELF', 'ALREADY_BLOCKING'],
res: {
type: 'object',
@ -57,13 +39,11 @@ export default define(meta, paramDef, async (ps, user) => {
const blocker = await Users.findOneByOrFail({ id: user.id });
// 自分自身
if (user.id === ps.userId) {
throw new ApiError(meta.errors.blockeeIsYourself);
}
if (user.id === ps.userId) throw new ApiError('BLOCKEE_IS_YOURSELF');
// Get blockee
const blockee = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});
@ -73,9 +53,7 @@ export default define(meta, paramDef, async (ps, user) => {
blockeeId: blockee.id,
});
if (exist != null) {
throw new ApiError(meta.errors.alreadyBlocking);
}
if (exist != null) throw new ApiError('ALREADY_BLOCKING');
await create(blocker, blockee);

View file

@ -17,25 +17,7 @@ export const meta = {
kind: 'write:blocks',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '8621d8bf-c358-4303-a066-5ea78610eb3f',
},
blockeeIsYourself: {
message: 'Blockee is yourself.',
code: 'BLOCKEE_IS_YOURSELF',
id: '06f6fac6-524b-473c-a354-e97a40ae6eac',
},
notBlocking: {
message: 'You are not blocking that user.',
code: 'NOT_BLOCKING',
id: '291b2efa-60c6-45c0-9f6a-045c8f9b02cd',
},
},
errors: ['NO_SUCH_USER', 'BLOCKEE_IS_YOURSELF', 'NOT_BLOCKING'],
res: {
type: 'object',
@ -54,16 +36,14 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
const blocker = await Users.findOneByOrFail({ id: user.id });
// Check if the blockee is yourself
if (user.id === ps.userId) {
throw new ApiError(meta.errors.blockeeIsYourself);
}
if (user.id === ps.userId) throw new ApiError('BLOCKEE_IS_YOURSELF');
const blocker = await Users.findOneByOrFail({ id: user.id });
// Get blockee
const blockee = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});
@ -73,9 +53,7 @@ export default define(meta, paramDef, async (ps, user) => {
blockeeId: blockee.id,
});
if (exist == null) {
throw new ApiError(meta.errors.notBlocking);
}
if (exist == null) throw new ApiError('NOT_BLOCKING');
// Delete blocking
await deleteBlocking(blocker, blockee);

View file

@ -17,13 +17,7 @@ export const meta = {
ref: 'Channel',
},
errors: {
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: 'cd1e9f3e-5a12-4ab4-96f6-5d0a2cc32050',
},
},
errors: ['NO_SUCH_FILE'],
} as const;
export const paramDef = {
@ -45,9 +39,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (banner == null) {
throw new ApiError(meta.errors.noSuchFile);
}
if (banner == null) throw new ApiError('NO_SUCH_FILE');
}
const channel = await Channels.insert({

View file

@ -11,13 +11,7 @@ export const meta = {
kind: 'write:channels',
errors: {
noSuchChannel: {
message: 'No such channel.',
code: 'NO_SUCH_CHANNEL',
id: 'c0031718-d573-4e85-928e-10039f1fbb68',
},
},
errors: ['NO_SUCH_CHANNEL'],
} as const;
export const paramDef = {
@ -34,9 +28,7 @@ export default define(meta, paramDef, async (ps, user) => {
id: ps.channelId,
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
if (channel == null) throw new ApiError('NO_SUCH_CHANNEL');
await ChannelFollowings.insert({
id: genId(),

View file

@ -13,13 +13,7 @@ export const meta = {
ref: 'Channel',
},
errors: {
noSuchChannel: {
message: 'No such channel.',
code: 'NO_SUCH_CHANNEL',
id: '6f6c314b-7486-4897-8966-c04a66a02923',
},
},
errors: ['NO_SUCH_CHANNEL'],
} as const;
export const paramDef = {
@ -36,9 +30,7 @@ export default define(meta, paramDef, async (ps, me) => {
id: ps.channelId,
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
if (channel == null) throw new ApiError('NO_SUCH_CHANNEL');
return await Channels.pack(channel, me);
});

View file

@ -19,13 +19,7 @@ export const meta = {
},
},
errors: {
noSuchChannel: {
message: 'No such channel.',
code: 'NO_SUCH_CHANNEL',
id: '4d0eeeba-a02c-4c3c-9966-ef60d38d2e7f',
},
},
errors: ['NO_SUCH_CHANNEL'],
} as const;
export const paramDef = {
@ -47,9 +41,7 @@ export default define(meta, paramDef, async (ps, user) => {
id: ps.channelId,
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
if (channel == null) throw new ApiError('NO_SUCH_CHANNEL');
//#region Construct query
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)

View file

@ -10,13 +10,7 @@ export const meta = {
kind: 'write:channels',
errors: {
noSuchChannel: {
message: 'No such channel.',
code: 'NO_SUCH_CHANNEL',
id: '19959ee9-0153-4c51-bbd9-a98c49dc59d6',
},
},
errors: ['NO_SUCH_CHANNEL'],
} as const;
export const paramDef = {
@ -33,9 +27,7 @@ export default define(meta, paramDef, async (ps, user) => {
id: ps.channelId,
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
if (channel == null) throw new ApiError('NO_SUCH_CHANNEL');
await ChannelFollowings.delete({
followerId: user.id,

View file

@ -15,25 +15,7 @@ export const meta = {
ref: 'Channel',
},
errors: {
noSuchChannel: {
message: 'No such channel.',
code: 'NO_SUCH_CHANNEL',
id: 'f9c5467f-d492-4c3c-9a8d-a70dacc86512',
},
accessDenied: {
message: 'You do not have edit privilege of the channel.',
code: 'ACCESS_DENIED',
id: '1fb7cb09-d46a-4fdf-b8df-057788cce513',
},
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: 'e86c14a4-0da2-4032-8df3-e737a04c7f3b',
},
},
errors: ['ACCESS_DENIED', 'NO_SUCH_CHANNEL', 'NO_SUCH_FILE'],
} as const;
export const paramDef = {
@ -53,13 +35,9 @@ export default define(meta, paramDef, async (ps, me) => {
id: ps.channelId,
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
if (channel == null) throw new ApiError('NO_SUCH_CHANNEL');
if (channel.userId !== me.id) {
throw new ApiError(meta.errors.accessDenied);
}
if (channel.userId !== me.id) throw new ApiError('ACCESS_DENIED', 'You are not the owner of this channel.');
// eslint:disable-next-line:no-unnecessary-initializer
let banner = undefined;
@ -69,9 +47,7 @@ export default define(meta, paramDef, async (ps, me) => {
userId: me.id,
});
if (banner == null) {
throw new ApiError(meta.errors.noSuchFile);
}
if (banner == null) throw new ApiError('NO_SUCH_FILE');
} else if (ps.bannerId === null) {
banner = null;
}

View file

@ -11,25 +11,7 @@ export const meta = {
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'd6e76cc0-a1b5-4c7c-a287-73fa9c716dcf',
},
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: 'fc8c0b49-c7a3-4664-a0a6-b418d386bb8b',
},
alreadyClipped: {
message: 'The note has already been clipped.',
code: 'ALREADY_CLIPPED',
id: '734806c4-542c-463a-9311-15c512803965',
},
},
errors: ['ALREADY_CLIPPED', 'NO_SUCH_CLIP', 'NO_SUCH_NOTE'],
} as const;
export const paramDef = {
@ -48,12 +30,10 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (clip == null) {
throw new ApiError(meta.errors.noSuchClip);
}
if (clip == null) throw new ApiError('NO_SUCH_CLIP');
const note = await getNote(ps.noteId, user).catch(err => {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError('NO_SUCH_NOTE');
throw err;
});
@ -62,9 +42,7 @@ export default define(meta, paramDef, async (ps, user) => {
clipId: clip.id,
});
if (exist != null) {
throw new ApiError(meta.errors.alreadyClipped);
}
if (exist != null) throw new ApiError('ALREADY_CLIPPED');
await ClipNotes.insert({
id: genId(),

View file

@ -9,13 +9,7 @@ export const meta = {
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: '70ca08ba-6865-4630-b6fb-8494759aa754',
},
},
errors: ['NO_SUCH_CLIP'],
} as const;
export const paramDef = {
@ -33,9 +27,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (clip == null) {
throw new ApiError(meta.errors.noSuchClip);
}
if (clip == null) throw new ApiError('NO_SUCH_CLIP');
await Clips.delete(clip.id);
});

View file

@ -13,13 +13,7 @@ export const meta = {
kind: 'read:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
},
},
errors: ['NO_SUCH_CLIP'],
res: {
type: 'array',
@ -49,12 +43,10 @@ export default define(meta, paramDef, async (ps, user) => {
id: ps.clipId,
});
if (clip == null) {
throw new ApiError(meta.errors.noSuchClip);
}
if (clip == null) throw new ApiError('NO_SUCH_CLIP');
if (!clip.isPublic && (user == null || (clip.userId !== user.id))) {
throw new ApiError(meta.errors.noSuchClip);
throw new ApiError('NO_SUCH_CLIP');
}
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)

View file

@ -10,19 +10,7 @@ export const meta = {
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'b80525c6-97f7-49d7-a42d-ebccd49cfd52',
},
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: 'aff017de-190e-434b-893e-33a9ff5049d8',
},
},
errors: ['NO_SUCH_CLIP', 'NO_SUCH_NOTE', 'NOT_CLIPPED'],
} as const;
export const paramDef = {
@ -41,17 +29,17 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (clip == null) {
throw new ApiError(meta.errors.noSuchClip);
}
if (clip == null) throw new ApiError('NO_SUCH_CLIP');
const note = await getNote(ps.noteId).catch(e => {
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError('NO_SUCH_NOTE');
throw e;
});
await ClipNotes.delete({
const { affected } = await ClipNotes.delete({
noteId: note.id,
clipId: clip.id,
});
if (affected === 0) throw new ApiError('NOT_CLIPPED');
});

View file

@ -9,13 +9,7 @@ export const meta = {
kind: 'read:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'c3c5fe33-d62c-44d2-9ea5-d997703f5c20',
},
},
errors: ['NO_SUCH_CLIP'],
res: {
type: 'object',
@ -39,12 +33,10 @@ export default define(meta, paramDef, async (ps, me) => {
id: ps.clipId,
});
if (clip == null) {
throw new ApiError(meta.errors.noSuchClip);
}
if (clip == null) throw new ApiError('NO_SUCH_CLIP');
if (!clip.isPublic && (me == null || (clip.userId !== me.id))) {
throw new ApiError(meta.errors.noSuchClip);
throw new ApiError('NO_SUCH_CLIP');
}
return await Clips.pack(clip);

View file

@ -9,13 +9,7 @@ export const meta = {
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'b4d92d70-b216-46fa-9a3f-a8c811699257',
},
},
errors: ['NO_SUCH_CLIP'],
res: {
type: 'object',
@ -43,9 +37,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (clip == null) {
throw new ApiError(meta.errors.noSuchClip);
}
if (clip == null) throw new ApiError('NO_SUCH_CLIP');
await Clips.update(clip.id, {
name: ps.name,

View file

@ -21,13 +21,7 @@ export const meta = {
},
},
errors: {
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: 'c118ece3-2e4b-4296-99d1-51756e32d232',
},
},
errors: ['NO_SUCH_FILE'],
} as const;
export const paramDef = {
@ -46,9 +40,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (file == null) {
throw new ApiError(meta.errors.noSuchFile);
}
if (file == null) throw new ApiError('NO_SUCH_FILE');
const notes = await Notes.createQueryBuilder('note')
.where(':file = ANY(note.fileIds)', { file: file.id })

View file

@ -28,13 +28,7 @@ export const meta = {
ref: 'DriveFile',
},
errors: {
invalidFileName: {
message: 'Invalid file name.',
code: 'INVALID_FILE_NAME',
id: 'f449b209-0c60-4e51-84d5-29486263bfd4',
},
},
errors: ['INTERNAL_ERROR', 'INVALID_FILE_NAME'],
} as const;
export const paramDef = {
@ -60,7 +54,7 @@ export default define(meta, paramDef, async (ps, user, _, file, cleanup) => {
} else if (name === 'blob') {
name = null;
} else if (!DriveFiles.validateFileName(name)) {
throw new ApiError(meta.errors.invalidFileName);
throw new ApiError('INVALID_FILE_NAME');
}
} else {
name = null;
@ -74,7 +68,7 @@ export default define(meta, paramDef, async (ps, user, _, file, cleanup) => {
if (e instanceof Error || typeof e === 'string') {
apiLogger.error(e);
}
throw new ApiError();
throw new ApiError('INTERNAL_ERROR');
} finally {
cleanup!();
}

View file

@ -13,19 +13,7 @@ export const meta = {
description: 'Delete an existing drive file.',
errors: {
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: '908939ec-e52b-4458-b395-1025195cea58',
},
accessDenied: {
message: 'Access denied.',
code: 'ACCESS_DENIED',
id: '5eb8d909-2540-4970-90b8-dd6f86088121',
},
},
errors: ['ACCESS_DENIED', 'NO_SUCH_FILE'],
} as const;
export const paramDef = {
@ -40,12 +28,10 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
const file = await DriveFiles.findOneBy({ id: ps.fileId });
if (file == null) {
throw new ApiError(meta.errors.noSuchFile);
}
if (file == null) throw new ApiError('NO_SUCH_FILE');
if ((!user.isAdmin && !user.isModerator) && (file.userId !== user.id)) {
throw new ApiError(meta.errors.accessDenied);
throw new ApiError('ACCESS_DENIED');
}
// Delete

View file

@ -18,19 +18,7 @@ export const meta = {
ref: 'DriveFile',
},
errors: {
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: '067bc436-2718-4795-b0fb-ecbe43949e31',
},
accessDenied: {
message: 'Access denied.',
code: 'ACCESS_DENIED',
id: '25b73c73-68b1-41d0-bad1-381cfdf6579f',
},
},
errors: ['ACCESS_DENIED', 'NO_SUCH_FILE'],
} as const;
export const paramDef = {
@ -69,12 +57,10 @@ export default define(meta, paramDef, async (ps, user) => {
});
}
if (file == null) {
throw new ApiError(meta.errors.noSuchFile);
}
if (file == null) throw new ApiError('NO_SUCH_FILE');
if ((!user.isAdmin && !user.isModerator) && (file.userId !== user.id)) {
throw new ApiError(meta.errors.accessDenied);
throw new ApiError('ACCESS_DENIED');
}
return await DriveFiles.pack(file, {

View file

@ -12,31 +12,7 @@ export const meta = {
description: 'Update the properties of a drive file.',
errors: {
invalidFileName: {
message: 'Invalid file name.',
code: 'INVALID_FILE_NAME',
id: '395e7156-f9f0-475e-af89-53c3c23080c2',
},
noSuchFile: {
message: 'No such file.',
code: 'NO_SUCH_FILE',
id: 'e7778c7e-3af9-49cd-9690-6dbc3e6c972d',
},
accessDenied: {
message: 'Access denied.',
code: 'ACCESS_DENIED',
id: '01a53b27-82fc-445b-a0c1-b558465a8ed2',
},
noSuchFolder: {
message: 'No such folder.',
code: 'NO_SUCH_FOLDER',
id: 'ea8fb7a5-af77-4a08-b608-c0218176cd73',
},
},
errors: ['ACCESS_DENIED', 'INVALID_FILE_NAME', 'NO_SUCH_FILE', 'NO_SUCH_FOLDER'],
res: {
type: 'object',
@ -61,17 +37,15 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
const file = await DriveFiles.findOneBy({ id: ps.fileId });
if (file == null) {
throw new ApiError(meta.errors.noSuchFile);
}
if (file == null) throw new ApiError('NO_SUCH_FILE');
if ((!user.isAdmin && !user.isModerator) && (file.userId !== user.id)) {
throw new ApiError(meta.errors.accessDenied);
throw new ApiError('ACCESS_DENIED');
}
if (ps.name) file.name = ps.name;
if (!DriveFiles.validateFileName(file.name)) {
throw new ApiError(meta.errors.invalidFileName);
throw new ApiError('INVALID_FILE_NAME');
}
if (ps.comment !== undefined) file.comment = ps.comment;
@ -87,9 +61,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (folder == null) {
throw new ApiError(meta.errors.noSuchFolder);
}
if (folder == null) throw new ApiError('NO_SUCH_FOLDER');
file.folderId = folder.id;
}

View file

@ -11,13 +11,7 @@ export const meta = {
kind: 'write:drive',
errors: {
noSuchFolder: {
message: 'No such folder.',
code: 'NO_SUCH_FOLDER',
id: '53326628-a00d-40a6-a3cd-8975105c0f95',
},
},
errors: ['NO_SUCH_FOLDER'],
res: {
type: 'object' as const,
@ -46,9 +40,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (parent == null) {
throw new ApiError(meta.errors.noSuchFolder);
}
if (parent == null) throw new ApiError('NO_SUCH_FOLDER');
}
// Create folder

View file

@ -10,19 +10,7 @@ export const meta = {
kind: 'write:drive',
errors: {
noSuchFolder: {
message: 'No such folder.',
code: 'NO_SUCH_FOLDER',
id: '1069098f-c281-440f-b085-f9932edbe091',
},
hasChildFilesOrFolders: {
message: 'This folder has child files or folders.',
code: 'HAS_CHILD_FILES_OR_FOLDERS',
id: 'b0fc8a17-963c-405d-bfbc-859a487295e1',
},
},
errors: ['HAS_CHILD_FILES_OR_FOLDERS', 'NO_SUCH_FOLDER'],
} as const;
export const paramDef = {
@ -41,9 +29,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (folder == null) {
throw new ApiError(meta.errors.noSuchFolder);
}
if (folder == null) throw new ApiError('NO_SUCH_FOLDER');
const [childFoldersCount, childFilesCount] = await Promise.all([
DriveFolders.countBy({ parentId: folder.id }),
@ -51,7 +37,7 @@ export default define(meta, paramDef, async (ps, user) => {
]);
if (childFoldersCount !== 0 || childFilesCount !== 0) {
throw new ApiError(meta.errors.hasChildFilesOrFolders);
throw new ApiError('HAS_CHILD_FILES_OR_FOLDERS');
}
await DriveFolders.delete(folder.id);

View file

@ -15,13 +15,7 @@ export const meta = {
ref: 'DriveFolder',
},
errors: {
noSuchFolder: {
message: 'No such folder.',
code: 'NO_SUCH_FOLDER',
id: 'd74ab9eb-bb09-4bba-bf24-fb58f761e1e9',
},
},
errors: ['NO_SUCH_FOLDER'],
} as const;
export const paramDef = {
@ -40,9 +34,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (folder == null) {
throw new ApiError(meta.errors.noSuchFolder);
}
if (folder == null) throw new ApiError('NO_SUCH_FOLDER');
return await DriveFolders.pack(folder, {
detail: true,

View file

@ -10,25 +10,7 @@ export const meta = {
kind: 'write:drive',
errors: {
noSuchFolder: {
message: 'No such folder.',
code: 'NO_SUCH_FOLDER',
id: 'f7974dac-2c0d-4a27-926e-23583b28e98e',
},
noSuchParentFolder: {
message: 'No such parent folder.',
code: 'NO_SUCH_PARENT_FOLDER',
id: 'ce104e3a-faaf-49d5-b459-10ff0cbbcaa1',
},
recursiveNesting: {
message: 'It can not be structured like nesting folders recursively.',
code: 'NO_SUCH_PARENT_FOLDER',
id: 'ce104e3a-faaf-49d5-b459-10ff0cbbcaa1',
},
},
errors: ['NO_SUCH_FOLDER', 'NO_SUCH_PARENT_FOLDER', 'RECURSIVE_FOLDER'],
res: {
type: 'object',
@ -55,15 +37,13 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (folder == null) {
throw new ApiError(meta.errors.noSuchFolder);
}
if (folder == null) throw new ApiError('NO_SUCH_FOLDER');
if (ps.name) folder.name = ps.name;
if (ps.parentId !== undefined) {
if (ps.parentId === folder.id) {
throw new ApiError(meta.errors.recursiveNesting);
throw new ApiError('RECURSIVE_FOLDER');
} else if (ps.parentId === null) {
folder.parentId = null;
} else {
@ -73,9 +53,7 @@ export default define(meta, paramDef, async (ps, user) => {
userId: user.id,
});
if (parent == null) {
throw new ApiError(meta.errors.noSuchParentFolder);
}
if (parent == null) throw new ApiError('NO_SUCH_PARENT_FOLDER');
// Check if the circular reference will occur
async function checkCircle(folderId: string): Promise<boolean> {
@ -95,7 +73,7 @@ export default define(meta, paramDef, async (ps, user) => {
if (parent.parentId !== null) {
if (await checkCircle(parent.parentId)) {
throw new ApiError(meta.errors.recursiveNesting);
throw new ApiError('RECURSIVE_FOLDER');
}
}

View file

@ -5,7 +5,8 @@ import { makePaginationQuery } from '../../common/make-pagination-query.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
requireCredential: true,
requireAdmin: true,
res: {
type: 'array',

View file

@ -5,7 +5,8 @@ import { makePaginationQuery } from '../../common/make-pagination-query.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
requireCredential: true,
requireAdmin: true,
res: {
type: 'array',

View file

@ -5,7 +5,7 @@ import define from '../../define.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
requireCredential: true,
res: {
type: 'array',

View file

@ -5,7 +5,7 @@ import define from '../../define.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
requireCredential: true,
res: {
oneOf: [{

View file

@ -6,7 +6,7 @@ import define from '../../define.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
requireCredential: true,
allowGet: true,
cacheSec: 60 * 60,

View file

@ -5,7 +5,7 @@ import { makePaginationQuery } from '../../common/make-pagination-query.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
requireCredential: true,
res: {
type: 'array',

View file

@ -8,7 +8,7 @@ const rssParser = new Parser();
export const meta = {
tags: ['meta'],
requireCredential: false,
requireCredential: true,
allowGet: true,
cacheSec: 60 * 3,
} as const;

View file

@ -18,37 +18,7 @@ export const meta = {
kind: 'write:following',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: 'fcd2eef9-a9b2-4c4f-8624-038099e90aa5',
},
followeeIsYourself: {
message: 'Followee is yourself.',
code: 'FOLLOWEE_IS_YOURSELF',
id: '26fbe7bb-a331-4857-af17-205b426669a9',
},
alreadyFollowing: {
message: 'You are already following that user.',
code: 'ALREADY_FOLLOWING',
id: '35387507-38c7-4cb9-9197-300b93783fa0',
},
blocking: {
message: 'You are blocking that user.',
code: 'BLOCKING',
id: '4e2206ec-aa4f-4960-b865-6c23ac38e2d9',
},
blocked: {
message: 'You are blocked by that user.',
code: 'BLOCKED',
id: 'c4ab57cc-4e41-45e9-bfd9-584f61e35ce0',
},
},
errors: ['ALREADY_FOLLOWING', 'BLOCKING', 'BLOCKED', 'FOLLOWEE_IS_YOURSELF', 'NO_SUCH_USER'],
res: {
type: 'object',
@ -70,13 +40,11 @@ export default define(meta, paramDef, async (ps, user) => {
const follower = user;
// 自分自身
if (user.id === ps.userId) {
throw new ApiError(meta.errors.followeeIsYourself);
}
if (user.id === ps.userId) throw new ApiError('FOLLOWEE_IS_YOURSELF');
// Get followee
const followee = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});
@ -86,16 +54,14 @@ export default define(meta, paramDef, async (ps, user) => {
followeeId: followee.id,
});
if (exist != null) {
throw new ApiError(meta.errors.alreadyFollowing);
}
if (exist != null) throw new ApiError('ALREADY_FOLLOWING');
try {
await create(follower, followee);
} catch (e) {
if (e instanceof IdentifiableError) {
if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') throw new ApiError(meta.errors.blocking);
if (e.id === '3338392a-f764-498d-8855-db939dcf8c48') throw new ApiError(meta.errors.blocked);
if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') throw new ApiError('BLOCKING');
if (e.id === '3338392a-f764-498d-8855-db939dcf8c48') throw new ApiError('BLOCKED');
}
throw e;
}

View file

@ -17,25 +17,7 @@ export const meta = {
kind: 'write:following',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '5b12c78d-2b28-4dca-99d2-f56139b42ff8',
},
followeeIsYourself: {
message: 'Followee is yourself.',
code: 'FOLLOWEE_IS_YOURSELF',
id: 'd9e400b9-36b0-4808-b1d8-79e707f1296c',
},
notFollowing: {
message: 'You are not following that user.',
code: 'NOT_FOLLOWING',
id: '5dbf82f5-c92b-40b1-87d1-6c8c0741fd09',
},
},
errors: ['FOLLOWEE_IS_YOURSELF', 'NO_SUCH_USER', 'NOT_FOLLOWING'],
res: {
type: 'object',
@ -57,13 +39,11 @@ export default define(meta, paramDef, async (ps, user) => {
const follower = user;
// Check if the followee is yourself
if (user.id === ps.userId) {
throw new ApiError(meta.errors.followeeIsYourself);
}
if (user.id === ps.userId) throw new ApiError('FOLLOWEE_IS_YOURSELF');
// Get followee
const followee = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});
@ -73,9 +53,7 @@ export default define(meta, paramDef, async (ps, user) => {
followeeId: followee.id,
});
if (exist == null) {
throw new ApiError(meta.errors.notFollowing);
}
if (exist == null) throw new ApiError('NOT_FOLLOWING');
await deleteFollowing(follower, followee);

View file

@ -17,25 +17,7 @@ export const meta = {
kind: 'write:following',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '5b12c78d-2b28-4dca-99d2-f56139b42ff8',
},
followerIsYourself: {
message: 'Follower is yourself.',
code: 'FOLLOWER_IS_YOURSELF',
id: '07dc03b9-03da-422d-885b-438313707662',
},
notFollowing: {
message: 'The other use is not following you.',
code: 'NOT_FOLLOWING',
id: '5dbf82f5-c92b-40b1-87d1-6c8c0741fd09',
},
},
errors: ['FOLLOWER_IS_YOURSELF', 'NO_SUCH_USER', 'NOT_FOLLOWING'],
res: {
type: 'object',
@ -57,13 +39,11 @@ export default define(meta, paramDef, async (ps, user) => {
const followee = user;
// Check if the follower is yourself
if (user.id === ps.userId) {
throw new ApiError(meta.errors.followerIsYourself);
}
if (user.id === ps.userId) throw new ApiError('FOLLOWER_IS_YOURSELF');
// Get follower
const follower = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});
@ -73,9 +53,7 @@ export default define(meta, paramDef, async (ps, user) => {
followeeId: followee.id,
});
if (exist == null) {
throw new ApiError(meta.errors.notFollowing);
}
if (exist == null) throw new ApiError('NOT_FOLLOWING');
await deleteFollowing(follower, followee);

View file

@ -10,18 +10,7 @@ export const meta = {
kind: 'write:following',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '66ce1645-d66c-46bb-8b79-96739af885bd',
},
noFollowRequest: {
message: 'No follow request.',
code: 'NO_FOLLOW_REQUEST',
id: 'bcde4f8b-0913-4614-8881-614e522fb041',
},
},
errors: ['NO_SUCH_USER', 'NO_SUCH_FOLLOW_REQUEST'],
} as const;
export const paramDef = {
@ -36,12 +25,12 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
// Fetch follower
const follower = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});
await acceptFollowRequest(user, follower).catch(e => {
if (e.id === '8884c2dd-5795-4ac9-b27e-6a01d38190f9') throw new ApiError(meta.errors.noFollowRequest);
if (e.id === '8884c2dd-5795-4ac9-b27e-6a01d38190f9') throw new ApiError('NO_SUCH_FOLLOW_REQUEST');
throw e;
});

View file

@ -12,19 +12,7 @@ export const meta = {
kind: 'write:following',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '4e68c551-fc4c-4e46-bb41-7d4a37bf9dab',
},
followRequestNotFound: {
message: 'Follow request not found.',
code: 'FOLLOW_REQUEST_NOT_FOUND',
id: '089b125b-d338-482a-9a09-e2622ac9f8d4',
},
},
errors: ['NO_SUCH_USER', 'NO_SUCH_FOLLOW_REQUEST'],
res: {
type: 'object',
@ -45,7 +33,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
// Fetch followee
const followee = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});
@ -53,7 +41,7 @@ export default define(meta, paramDef, async (ps, user) => {
await cancelFollowRequest(followee, user);
} catch (e) {
if (e instanceof IdentifiableError) {
if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError(meta.errors.followRequestNotFound);
if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError('NO_SUCH_FOLLOW_REQUEST');
}
throw e;
}

View file

@ -10,13 +10,7 @@ export const meta = {
kind: 'write:following',
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: 'abc2ffa6-25b2-4380-ba99-321ff3a94555',
},
},
errors: ['NO_SUCH_USER'],
} as const;
export const paramDef = {
@ -31,7 +25,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => {
// Fetch follower
const follower = await getUser(ps.userId).catch(e => {
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
if (e.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError('NO_SUCH_USER');
throw e;
});

Some files were not shown because too many files have changed in this diff Show more