summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/endpoints/i/2fa/done.ts2
-rw-r--r--src/server/api/endpoints/i/2fa/register.ts2
-rw-r--r--src/server/api/endpoints/i/2fa/unregister.ts2
-rw-r--r--src/server/api/endpoints/i/change-password.ts2
-rw-r--r--src/server/api/endpoints/i/delete-account.ts2
-rw-r--r--src/server/api/endpoints/i/regenerate-token.ts2
-rw-r--r--src/server/api/endpoints/i/update-email.ts2
-rw-r--r--src/server/api/endpoints/i/update.ts33
-rw-r--r--src/server/api/endpoints/notes/polls/vote.ts2
-rw-r--r--src/server/api/openapi/schemas.ts1
-rw-r--r--src/server/api/private/signin.ts2
11 files changed, 29 insertions, 23 deletions
diff --git a/src/server/api/endpoints/i/2fa/done.ts b/src/server/api/endpoints/i/2fa/done.ts
index e23678dcbb..c134e1b226 100644
--- a/src/server/api/endpoints/i/2fa/done.ts
+++ b/src/server/api/endpoints/i/2fa/done.ts
@@ -19,7 +19,7 @@ export const meta = {
export default define(meta, async (ps, user) => {
const token = ps.token.replace(/\s/g, '');
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
if (profile.twoFactorTempSecret == null) {
throw new Error('二段階認証の設定が開始されていません');
diff --git a/src/server/api/endpoints/i/2fa/register.ts b/src/server/api/endpoints/i/2fa/register.ts
index 76d79b3a49..bd46b7c68c 100644
--- a/src/server/api/endpoints/i/2fa/register.ts
+++ b/src/server/api/endpoints/i/2fa/register.ts
@@ -20,7 +20,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// Compare password
const same = await bcrypt.compare(ps.password, profile.password!);
diff --git a/src/server/api/endpoints/i/2fa/unregister.ts b/src/server/api/endpoints/i/2fa/unregister.ts
index 9c7857e7ef..99483143cc 100644
--- a/src/server/api/endpoints/i/2fa/unregister.ts
+++ b/src/server/api/endpoints/i/2fa/unregister.ts
@@ -17,7 +17,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// Compare password
const same = await bcrypt.compare(ps.password, profile.password!);
diff --git a/src/server/api/endpoints/i/change-password.ts b/src/server/api/endpoints/i/change-password.ts
index 0dda125b9c..07d2d864d2 100644
--- a/src/server/api/endpoints/i/change-password.ts
+++ b/src/server/api/endpoints/i/change-password.ts
@@ -21,7 +21,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// Compare password
const same = await bcrypt.compare(ps.currentPassword, profile.password!);
diff --git a/src/server/api/endpoints/i/delete-account.ts b/src/server/api/endpoints/i/delete-account.ts
index 389d0b3212..8ec85c9f41 100644
--- a/src/server/api/endpoints/i/delete-account.ts
+++ b/src/server/api/endpoints/i/delete-account.ts
@@ -17,7 +17,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// Compare password
const same = await bcrypt.compare(ps.password, profile.password!);
diff --git a/src/server/api/endpoints/i/regenerate-token.ts b/src/server/api/endpoints/i/regenerate-token.ts
index 56c0362c88..e27cf0b18c 100644
--- a/src/server/api/endpoints/i/regenerate-token.ts
+++ b/src/server/api/endpoints/i/regenerate-token.ts
@@ -19,7 +19,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// Compare password
const same = await bcrypt.compare(ps.password, profile.password!);
diff --git a/src/server/api/endpoints/i/update-email.ts b/src/server/api/endpoints/i/update-email.ts
index 15c62a9d08..e02f53a643 100644
--- a/src/server/api/endpoints/i/update-email.ts
+++ b/src/server/api/endpoints/i/update-email.ts
@@ -33,7 +33,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// Compare password
const same = await bcrypt.compare(ps.password, profile.password!);
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index d06ab621c6..2951072cf6 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -13,6 +13,7 @@ import { ApiError } from '../../error';
import { Users, DriveFiles, UserProfiles } from '../../../../models';
import { User } from '../../../../models/entities/user';
import { UserProfile } from '../../../../models/entities/user-profile';
+import { ensure } from '../../../../prelude/ensure';
export const meta = {
desc: {
@@ -157,22 +158,24 @@ export default define(meta, async (ps, user, app) => {
const isSecure = user != null && app == null;
const updates = {} as Partial<User>;
- const profile = {} as Partial<UserProfile>;
+ const profileUpdates = {} as Partial<UserProfile>;
+
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
if (ps.name !== undefined) updates.name = ps.name;
- if (ps.description !== undefined) profile.description = ps.description;
+ if (ps.description !== undefined) profileUpdates.description = ps.description;
//if (ps.lang !== undefined) updates.lang = ps.lang;
- if (ps.location !== undefined) profile.location = ps.location;
- if (ps.birthday !== undefined) profile.birthday = ps.birthday;
+ if (ps.location !== undefined) profileUpdates.location = ps.location;
+ if (ps.birthday !== undefined) profileUpdates.birthday = ps.birthday;
if (ps.avatarId !== undefined) updates.avatarId = ps.avatarId;
if (ps.bannerId !== undefined) updates.bannerId = ps.bannerId;
if (typeof ps.isLocked == 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isBot == 'boolean') updates.isBot = ps.isBot;
- if (typeof ps.carefulBot == 'boolean') profile.carefulBot = ps.carefulBot;
- if (typeof ps.autoAcceptFollowed == 'boolean') profile.autoAcceptFollowed = ps.autoAcceptFollowed;
+ if (typeof ps.carefulBot == 'boolean') profileUpdates.carefulBot = ps.carefulBot;
+ if (typeof ps.autoAcceptFollowed == 'boolean') profileUpdates.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.isCat == 'boolean') updates.isCat = ps.isCat;
- if (typeof ps.autoWatch == 'boolean') profile.autoWatch = ps.autoWatch;
- if (typeof ps.alwaysMarkNsfw == 'boolean') profile.alwaysMarkNsfw = ps.alwaysMarkNsfw;
+ if (typeof ps.autoWatch == 'boolean') profileUpdates.autoWatch = ps.autoWatch;
+ if (typeof ps.alwaysMarkNsfw == 'boolean') profileUpdates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
if (ps.avatarId) {
const avatar = await DriveFiles.findOne(ps.avatarId);
@@ -201,16 +204,20 @@ export default define(meta, async (ps, user, app) => {
}
//#region emojis/tags
+
let emojis = [] as string[];
let tags = [] as string[];
- if (updates.name != null) {
- const tokens = parsePlain(updates.name);
+ const newName = updates.name === undefined ? user.name : updates.name;
+ const newDescription = profileUpdates.description === undefined ? profile.description : profileUpdates.description;
+
+ if (newName != null) {
+ const tokens = parsePlain(newName);
emojis = emojis.concat(extractEmojis(tokens!));
}
- if (profile.description != null) {
- const tokens = parse(profile.description);
+ if (newDescription != null) {
+ const tokens = parse(newDescription);
emojis = emojis.concat(extractEmojis(tokens!));
tags = extractHashtags(tokens!).map(tag => tag.toLowerCase());
}
@@ -224,7 +231,7 @@ export default define(meta, async (ps, user, app) => {
//#endregion
if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
- if (Object.keys(profile).length > 0) await UserProfiles.update({ userId: user.id }, profile);
+ if (Object.keys(profileUpdates).length > 0) await UserProfiles.update({ userId: user.id }, profileUpdates);
const iObj = await Users.pack(user.id, user, {
detail: true,
diff --git a/src/server/api/endpoints/notes/polls/vote.ts b/src/server/api/endpoints/notes/polls/vote.ts
index d13405597d..0510e70d3e 100644
--- a/src/server/api/endpoints/notes/polls/vote.ts
+++ b/src/server/api/endpoints/notes/polls/vote.ts
@@ -150,7 +150,7 @@ export default define(meta, async (ps, user) => {
}
});
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// この投稿をWatchする
if (profile.autoWatch !== false) {
diff --git a/src/server/api/openapi/schemas.ts b/src/server/api/openapi/schemas.ts
index 5992fee835..65826d9321 100644
--- a/src/server/api/openapi/schemas.ts
+++ b/src/server/api/openapi/schemas.ts
@@ -1,4 +1,3 @@
-
export const schemas = {
Error: {
type: 'object',
diff --git a/src/server/api/private/signin.ts b/src/server/api/private/signin.ts
index 676546f2aa..02361a139d 100644
--- a/src/server/api/private/signin.ts
+++ b/src/server/api/private/signin.ts
@@ -46,7 +46,7 @@ export default async (ctx: Koa.BaseContext) => {
return;
}
- const profile = await UserProfiles.findOne({ userId: user.id }).then(ensure);
+ const profile = await UserProfiles.findOne(user.id).then(ensure);
// Compare password
const same = await bcrypt.compare(password, profile.password!);