mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-15 04:43:08 +02:00
f0a29721c9
* wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * ✌️ * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * 🍕 * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * ✌️ * clean up * docs * Update push.ts * wip * Update api.ts * wip * ✌️ * Update make-pagination-query.ts * ✌️ * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * 🎨 * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * ✌️ * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * 🎨 * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * ✌️ * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * 🍣 * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * 🕓 * Fix bug * Add test * Add test * rename * Fix bug
242 lines
6.4 KiB
TypeScript
242 lines
6.4 KiB
TypeScript
import $ from 'cafy';
|
|
import { ID } from '../../../../misc/cafy-id';
|
|
import { publishMainStream } from '../../../../services/stream';
|
|
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
|
|
import { publishToFollowers } from '../../../../services/i/update';
|
|
import define from '../../define';
|
|
import { parse, parsePlain } from '../../../../mfm/parse';
|
|
import extractEmojis from '../../../../misc/extract-emojis';
|
|
import extractHashtags from '../../../../misc/extract-hashtags';
|
|
import * as langmap from 'langmap';
|
|
import { updateHashtag } from '../../../../services/update-hashtag';
|
|
import { ApiError } from '../../error';
|
|
import { Users, DriveFiles } from '../../../../models';
|
|
|
|
export const meta = {
|
|
desc: {
|
|
'ja-JP': 'アカウント情報を更新します。',
|
|
'en-US': 'Update myself'
|
|
},
|
|
|
|
tags: ['account'],
|
|
|
|
requireCredential: true,
|
|
|
|
kind: 'write:account',
|
|
|
|
params: {
|
|
name: {
|
|
validator: $.optional.nullable.str.pipe(Users.isValidName),
|
|
desc: {
|
|
'ja-JP': '名前(ハンドルネームやニックネーム)'
|
|
}
|
|
},
|
|
|
|
description: {
|
|
validator: $.optional.nullable.str.pipe(Users.isValidDescription),
|
|
desc: {
|
|
'ja-JP': 'アカウントの説明や自己紹介'
|
|
}
|
|
},
|
|
|
|
lang: {
|
|
validator: $.optional.nullable.str.or(Object.keys(langmap)),
|
|
desc: {
|
|
'ja-JP': '言語'
|
|
}
|
|
},
|
|
|
|
location: {
|
|
validator: $.optional.nullable.str.pipe(Users.isValidLocation),
|
|
desc: {
|
|
'ja-JP': '住んでいる地域、所在'
|
|
}
|
|
},
|
|
|
|
birthday: {
|
|
validator: $.optional.nullable.str.pipe(Users.isValidBirthday),
|
|
desc: {
|
|
'ja-JP': '誕生日 (YYYY-MM-DD形式)'
|
|
}
|
|
},
|
|
|
|
avatarId: {
|
|
validator: $.optional.nullable.type(ID),
|
|
desc: {
|
|
'ja-JP': 'アイコンに設定する画像のドライブファイルID'
|
|
}
|
|
},
|
|
|
|
bannerId: {
|
|
validator: $.optional.nullable.type(ID),
|
|
desc: {
|
|
'ja-JP': 'バナーに設定する画像のドライブファイルID'
|
|
}
|
|
},
|
|
|
|
isLocked: {
|
|
validator: $.optional.bool,
|
|
desc: {
|
|
'ja-JP': '鍵アカウントか否か'
|
|
}
|
|
},
|
|
|
|
carefulBot: {
|
|
validator: $.optional.bool,
|
|
desc: {
|
|
'ja-JP': 'Botからのフォローを承認制にするか'
|
|
}
|
|
},
|
|
|
|
autoAcceptFollowed: {
|
|
validator: $.optional.bool,
|
|
desc: {
|
|
'ja-JP': 'フォローしているユーザーからのフォローリクエストを自動承認するか'
|
|
}
|
|
},
|
|
|
|
isBot: {
|
|
validator: $.optional.bool,
|
|
desc: {
|
|
'ja-JP': 'Botか否か'
|
|
}
|
|
},
|
|
|
|
isCat: {
|
|
validator: $.optional.bool,
|
|
desc: {
|
|
'ja-JP': '猫か否か'
|
|
}
|
|
},
|
|
|
|
autoWatch: {
|
|
validator: $.optional.bool,
|
|
desc: {
|
|
'ja-JP': '投稿の自動ウォッチをするか否か'
|
|
}
|
|
},
|
|
|
|
alwaysMarkNsfw: {
|
|
validator: $.optional.bool,
|
|
desc: {
|
|
'ja-JP': 'アップロードするメディアをデフォルトで「閲覧注意」として設定するか'
|
|
}
|
|
},
|
|
},
|
|
|
|
errors: {
|
|
noSuchAvatar: {
|
|
message: 'No such avatar file.',
|
|
code: 'NO_SUCH_AVATAR',
|
|
id: '539f3a45-f215-4f81-a9a8-31293640207f'
|
|
},
|
|
|
|
noSuchBanner: {
|
|
message: 'No such banner file.',
|
|
code: 'NO_SUCH_BANNER',
|
|
id: '0d8f5629-f210-41c2-9433-735831a58595'
|
|
},
|
|
|
|
avatarNotAnImage: {
|
|
message: 'The file specified as an avatar is not an image.',
|
|
code: 'AVATAR_NOT_AN_IMAGE',
|
|
id: 'f419f9f8-2f4d-46b1-9fb4-49d3a2fd7191'
|
|
},
|
|
|
|
bannerNotAnImage: {
|
|
message: 'The file specified as a banner is not an image.',
|
|
code: 'BANNER_NOT_AN_IMAGE',
|
|
id: '75aedb19-2afd-4e6d-87fc-67941256fa60'
|
|
}
|
|
}
|
|
};
|
|
|
|
export default define(meta, async (ps, user, app) => {
|
|
const isSecure = user != null && app == null;
|
|
|
|
const updates = {} as any;
|
|
|
|
if (ps.name !== undefined) updates.name = ps.name;
|
|
if (ps.description !== undefined) updates.description = ps.description;
|
|
if (ps.lang !== undefined) updates.lang = ps.lang;
|
|
if (ps.location !== undefined) updates.location = ps.location;
|
|
if (ps.birthday !== undefined) updates.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') updates.carefulBot = ps.carefulBot;
|
|
if (typeof ps.autoAcceptFollowed == 'boolean') updates.autoAcceptFollowed = ps.autoAcceptFollowed;
|
|
if (typeof ps.isCat == 'boolean') updates.isCat = ps.isCat;
|
|
if (typeof ps.autoWatch == 'boolean') updates.autoWatch = ps.autoWatch;
|
|
if (typeof ps.alwaysMarkNsfw == 'boolean') updates.alwaysMarkNsfw = ps.alwaysMarkNsfw;
|
|
|
|
if (ps.avatarId) {
|
|
const avatar = await DriveFiles.findOne(ps.avatarId);
|
|
|
|
if (avatar == null || avatar.userId !== user.id) throw new ApiError(meta.errors.noSuchAvatar);
|
|
if (!avatar.type.startsWith('image/')) throw new ApiError(meta.errors.avatarNotAnImage);
|
|
|
|
updates.avatarUrl = avatar.thumbnailUrl;
|
|
|
|
if (avatar.properties.avgColor) {
|
|
updates.avatarColor = avatar.properties.avgColor;
|
|
}
|
|
}
|
|
|
|
if (ps.bannerId) {
|
|
const banner = await DriveFiles.findOne(ps.bannerId);
|
|
|
|
if (banner == null || banner.userId !== user.id) throw new ApiError(meta.errors.noSuchBanner);
|
|
if (!banner.type.startsWith('image/')) throw new ApiError(meta.errors.bannerNotAnImage);
|
|
|
|
updates.bannerUrl = banner.webpublicUrl;
|
|
|
|
if (banner.properties.avgColor) {
|
|
updates.bannerColor = banner.properties.avgColor;
|
|
}
|
|
}
|
|
|
|
//#region emojis/tags
|
|
let emojis = [] as string[];
|
|
let tags = [] as string[];
|
|
|
|
if (updates.name != null) {
|
|
const tokens = parsePlain(updates.name);
|
|
emojis = emojis.concat(extractEmojis(tokens));
|
|
}
|
|
|
|
if (updates.description != null) {
|
|
const tokens = parse(updates.description);
|
|
emojis = emojis.concat(extractEmojis(tokens));
|
|
tags = extractHashtags(tokens).map(tag => tag.toLowerCase());
|
|
}
|
|
|
|
updates.emojis = emojis;
|
|
updates.tags = tags;
|
|
|
|
// ハッシュタグ更新
|
|
for (const tag of tags) updateHashtag(user, tag, true, true);
|
|
for (const tag of user.tags.filter(x => !tags.includes(x))) updateHashtag(user, tag, true, false);
|
|
//#endregion
|
|
|
|
await Users.update(user.id, updates);
|
|
|
|
const iObj = await Users.pack(user.id, user, {
|
|
detail: true,
|
|
includeSecrets: isSecure
|
|
});
|
|
|
|
// Publish meUpdated event
|
|
publishMainStream(user.id, 'meUpdated', iObj);
|
|
|
|
// 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認
|
|
if (user.isLocked && ps.isLocked === false) {
|
|
acceptAllFollowRequests(user);
|
|
}
|
|
|
|
// フォロワーにUpdateを配信
|
|
publishToFollowers(user.id);
|
|
|
|
return iObj;
|
|
});
|