Skip to content

Commit

Permalink
Merge pull request #79 from mebtte/beta
Browse files Browse the repository at this point in the history
i18n
  • Loading branch information
MEBTTE committed Jul 24, 2023
2 parents 9eba237 + b2126bd commit 42752bf
Show file tree
Hide file tree
Showing 154 changed files with 1,091 additions and 943 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = {
'react/static-property-placement': 'off',
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
'react/no-array-index-key': 'warn',

'no-nested-ternary': 'off',
'prefer-promise-reject-errors': 'error',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker_build_and_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: mebtte/cicada
short-description: "A multi-user music service for self-host."
short-description: "A multi-user music service for self-hosting."
readme-filepath: "./docker.md"

- run: ./docker_build_and_push.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context as BaseContext } from 'koa';
import { Context as BaseContext } from '../../constants';
import { ParasiteMiddleware } from '../../middlewares/parasite';
import { AuthorizeMiddleware } from '../../middlewares/authorize';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async (ctx: Context) => {
[id, ctx.user.id],
);
if (!sharedMusicbillInvitation) {
return ctx.except(ExceptionCode.SHARED_MUSICBILL_INVITATION_NOT_EXIST);
return ctx.except(ExceptionCode.SHARED_MUSICBILL_INVITATION_NOT_EXISTED);
}

await getDB().run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async (ctx: Context) => {
]);

if (!musicbill) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}
if (musicbill.userId !== ctx.user.id) {
const sharedUser = await getDB().get(
Expand All @@ -48,19 +48,19 @@ export default async (ctx: Context) => {
[musicbillId, ctx.user.id],
);
if (!sharedUser) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}
}

if (!music) {
return ctx.except(ExceptionCode.MUSIC_NOT_EXIST);
return ctx.except(ExceptionCode.MUSIC_NOT_EXISTED);
}

const musicbillMusic = await getMusicbillMusic(musicbillId, musicId, [
MusicbillMusicProperty.ID,
]);
if (musicbillMusic) {
return ctx.except(ExceptionCode.MUSIC_IN_MUSICBILL_ALREADY);
return ctx.except(ExceptionCode.MUSIC_ALREADY_EXISTED_IN_MUSICBILL);
}

await addMusicbillMusic(musicbillId, musicId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async (ctx: Context) => {
MusicbillProperty.USER_ID,
]);
if (!musicbill) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}

const [sharedUserList, user] = await Promise.all([
Expand All @@ -57,16 +57,16 @@ export default async (ctx: Context) => {
musicbill.userId !== ctx.user.id &&
!sharedUserList.find((u) => u.sharedUserId === ctx.user.id && u.accepted)
) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}
if (!user) {
return ctx.except(ExceptionCode.USER_NOT_EXIST);
return ctx.except(ExceptionCode.USER_NOT_EXISTED);
}
if (musicbill.userId === user.id) {
return ctx.except(ExceptionCode.SHARED_MUSICBILL_CAN_NOT_INVITE_OWNER);
return ctx.except(ExceptionCode.CAN_NOT_INVITE_MUSICBILL_OWNER);
}
if (sharedUserList.find((u) => u.sharedUserId === musicbill.userId)) {
return ctx.except(ExceptionCode.SHARED_MUSICBILL_CAN_NOT_INVITE_REPEATLY);
return ctx.except(ExceptionCode.REPEATED_SHARED_MUSICBILL_INVITATION);
}

await getDB().run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import generateRandomInteger from '#/utils/generate_random_integer';
import { REMARK_MAX_LENGTH } from '#/constants/user';
import { sendEmail } from '@/platform/email';
import { getUserByEmail } from '@/db/user';
import { BRAND_NAME } from '#/constants';
import { UserProperty } from '@/constants/db_definition';
import { Context } from '../constants';

Expand Down Expand Up @@ -45,13 +44,14 @@ export default async (ctx: Context) => {

const user = await getUserByEmail(email, [UserProperty.ID]);
if (user) {
return ctx.except(ExceptionCode.EMAIL_EXISTED);
return ctx.except(ExceptionCode.EMAIL_ALREADY_REGISTERED);
}

await sendEmail({
to: email,
title: `欢迎使用${BRAND_NAME}`,
title: `欢迎使用${ctx.t('cicada')}`,
html: generateEmailHtml({ accessOrigin }),
fromName: ctx.t('cicada'),
});

const id = generateRandomInteger(1_0000, 1000_0000).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export default async (ctx: Context) => {

const user = await getUserById(id, [UserProperty.ID, UserProperty.ADMIN]);
if (!user) {
return ctx.except(ExceptionCode.USER_NOT_EXIST);
return ctx.except(ExceptionCode.USER_NOT_EXISTED);
}
if (user.admin) {
return ctx.except(ExceptionCode.ADMIN_USER_CAN_NOT_BE_DELETED);
return ctx.except(ExceptionCode.CAN_NOT_DELETE_ADMIN);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default async (ctx: Context) => {
UserProperty.MUSIC_PLAY_RECORD_INDATE,
]);
if (!user) {
return ctx.except(ExceptionCode.USER_NOT_EXIST);
return ctx.except(ExceptionCode.USER_NOT_EXISTED);
}

return KEY_MAP_HANDLER[key as AdminAllowUpdateKey]({ ctx, user, value });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async (ctx: Context) => {

const user = await getUserById(id, [UserProperty.ID, UserProperty.ADMIN]);
if (!user) {
return ctx.except(ExceptionCode.USER_NOT_EXIST);
return ctx.except(ExceptionCode.USER_NOT_EXISTED);
}
if (user.admin) {
return ctx.except(ExceptionCode.USER_IS_ADMIN_ALREADY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export default async (ctx: Context) => {
}),
]);
if (!musicbill || !musicbill.public) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}
if (musicbillCollection) {
return ctx.except(ExceptionCode.COLLECT_MUSICBILL_REPEATLY);
return ctx.except(ExceptionCode.CAN_NOT_COLLECT_MUSICBILL_REPEATLY);
}

await getDB().run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ export default async (ctx: Context) => {

const assetExist = await exist(getAssetFilePath(asset, AssetType.MUSIC));
if (!assetExist) {
return ctx.except(ExceptionCode.ASSET_NOT_EXIST);
return ctx.except(ExceptionCode.ASSET_NOT_EXISTED);
}

const singerIdList = singerIds.split(',');
const singerList = await getSingerListByIds(singerIdList, [
SingerProperty.ID,
]);
if (singerList.length !== singerIdList.length) {
return ctx.except(ExceptionCode.SINGER_NOT_EXIST);
return ctx.except(ExceptionCode.SINGER_NOT_EXISTED);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default async (ctx: Context) => {
if (!force) {
const existSinger = await getSingerByName(name, [SingerProperty.ID]);
if (existSinger) {
return ctx.except(ExceptionCode.SINGER_EXIST);
return ctx.except(ExceptionCode.SINGER_ALREADY_EXISTED);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export default async (ctx: Context) => {

const music = await getMusicById(id, Object.values(MusicProperty));
if (!music || (!ctx.user.admin && music.createUserId !== ctx.user.id)) {
return ctx.except(ExceptionCode.MUSIC_NOT_EXIST);
return ctx.except(ExceptionCode.MUSIC_NOT_EXISTED);
}

const forkList = await getMusicForkList(id, [
MusicForkProperty.ID,
MusicForkProperty.MUSIC_ID,
]);
if (forkList.length) {
return ctx.except(ExceptionCode.MUSIC_HAS_FORK_AND_CAN_NOT_BE_DELETED);
return ctx.except(ExceptionCode.MUSIC_FORKED_BY_OTHER_CAN_NOT_BE_DELETED);
}

await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async (ctx: Context) => {
[id],
);
if (!musicPlayRecord || ctx.user.id !== musicPlayRecord.userId) {
return ctx.except(ExceptionCode.MUSIC_PLAY_RECORD_NOT_EXIST);
return ctx.except(ExceptionCode.MUSIC_PLAY_RECORD_NOT_EXISTED);
}

await getDB().run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default async (ctx: Context) => {

const musicbill = await getMusicbillById(id, [MusicbillProperty.USER_ID]);
if (!musicbill || musicbill.userId !== ctx.user.id) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}

await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async (ctx: Context) => {
MusicbillProperty.USER_ID,
]);
if (!musicbill) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}

if (ctx.user.id !== musicbill.userId && ctx.user.id !== userId) {
Expand All @@ -54,7 +54,7 @@ export default async (ctx: Context) => {
[musicbillId, userId],
);
if (!sharedUser) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}

await getDB().run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export default async (ctx: Context) => {
MusicProperty.TYPE,
]);
if (!music) {
return ctx.except(ExceptionCode.MUSIC_NOT_EXIST);
return ctx.except(ExceptionCode.MUSIC_NOT_EXISTED);
}
if (music.type === MusicType.INSTRUMENT) {
return ctx.except(ExceptionCode.INSTRUMENT_NO_LYRIC);
if (music.type === MusicType.INSTRUMENTAL) {
return ctx.except(ExceptionCode.INSTRUMENTAL_HAS_NO_LYRIC);
}

const lyrics = await getLyricListByMusicId(musicId, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default async (ctx: Context) => {
MusicProperty.YEAR,
]);
if (!music) {
return ctx.except(ExceptionCode.MUSIC_NOT_EXIST);
return ctx.except(ExceptionCode.MUSIC_NOT_EXISTED);
}
const [createUser, forkList, forkFromList, musicbillCount] =
await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default async (ctx: Context) => {
[id],
);
if (!musicbill) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}
const sharedUserList = await getDB().all<
Pick<
Expand Down Expand Up @@ -97,7 +97,7 @@ export default async (ctx: Context) => {
musicbill.userId !== ctx.user.id &&
(!sharedUser || sharedUser.accepted !== 1)
) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}

const musicList = await getDB().all<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ export default async (ctx: Context) => {
MusicbillProperty.USER_ID,
]);
if (!musicbill || !musicbill.public) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}

const [user, musicList, collectionCount, musicbillCollection] =
await Promise.all([
getUserById(musicbill.userId, [
UserProperty.ID,
UserProperty.NICKNAME,
UserProperty.AVATAR,
]),
getUserById(musicbill.userId, [UserProperty.ID, UserProperty.NICKNAME]),
getDB().all<
Pick<
Music,
Expand Down Expand Up @@ -119,10 +115,7 @@ export default async (ctx: Context) => {
MusicbillProperty.USER_ID,
]),
cover: getAssetPublicPath(musicbill.cover, AssetType.MUSICBILL_COVER),
user: {
...user!,
avatar: getAssetPublicPath(user!.avatar, AssetType.USER_AVATAR),
},
user: user!,
musicList: musicList.map((m) => ({
...m,
aliases: m.aliases ? m.aliases.split(ALIAS_DIVIDER) : [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async (ctx: Context) => {
SingerProperty.CREATE_USER_ID,
]);
if (!singer) {
return ctx.except(ExceptionCode.SINGER_NOT_EXIST);
return ctx.except(ExceptionCode.SINGER_NOT_EXISTED);
}

const [createUser, musicList, editable] = await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async (ctx: Context) => {

const singer = await getSingerById(id, [SingerProperty.CREATE_USER_ID]);
if (!singer) {
return ctx.except(ExceptionCode.SINGER_NOT_EXIST);
return ctx.except(ExceptionCode.SINGER_NOT_EXISTED);
}
if (singer.createUserId !== ctx.user.id) {
const editable = await getDB().get<
Expand All @@ -45,7 +45,7 @@ export default async (ctx: Context) => {
[ctx.user.id, id],
);
if (!editable) {
return ctx.except(ExceptionCode.SINGER_NOT_EXIST);
return ctx.except(ExceptionCode.SINGER_NOT_EXISTED);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async (ctx: Context) => {
UserProperty.NICKNAME,
]);
if (!user) {
return ctx.except(ExceptionCode.USER_NOT_EXIST);
return ctx.except(ExceptionCode.USER_NOT_EXISTED);
}

const [musicbillList, musicList] = await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default async (ctx: Context) => {
MusicbillProperty.USER_ID,
]);
if (!musicbill) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}
if (musicbill.userId !== ctx.user.id) {
const sharedUser = await getDB().get(
Expand All @@ -46,15 +46,15 @@ export default async (ctx: Context) => {
[musicbillId, ctx.user.id],
);
if (!sharedUser) {
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXIST);
return ctx.except(ExceptionCode.MUSICBILL_NOT_EXISTED);
}
}

const musicbillMusic = await getMusicbillMusic(musicbillId, musicId, [
MusicbillMusicProperty.ID,
]);
if (!musicbillMusic) {
return ctx.except(ExceptionCode.MUSIC_NOT_IN_MUSICBILL);
return ctx.except(ExceptionCode.MUSIC_NOT_EXISTED_IN_MUSICBILL);
}

await removeMusicbillMusicById(musicbillMusic.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async (ctx: Context) => {
properties: [PublicMusicbillCollectionProperty.ID],
});
if (!musicbillCollection) {
return ctx.except(ExceptionCode.NOT_COLLECT_MUSICBILL_YET);
return ctx.except(ExceptionCode.MUSICBILL_NOT_COLLECTED);
}

await getDB().run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default async (ctx: Context) => {
MusicProperty.YEAR,
]);
if (!music || (!ctx.user.admin && music.createUserId !== ctx.user.id)) {
return ctx.except(ExceptionCode.MUSIC_NOT_EXIST);
return ctx.except(ExceptionCode.MUSIC_NOT_EXISTED);
}

await KEY_MAP_HANDLER[key as AllowUpdateKey]({ ctx, music, value });
Expand Down
Loading

0 comments on commit 42752bf

Please sign in to comment.