Skip to content

Commit

Permalink
Merge pull request #131 from mebtte/beta
Browse files Browse the repository at this point in the history
stop timer
  • Loading branch information
mebtte authored Jun 21, 2024
2 parents 3b97e1f + d81d48e commit 678bec0
Show file tree
Hide file tree
Showing 84 changed files with 492 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ COPY build/cicada /bin/cicada
ENTRYPOINT ["/bin/cicada"]

LABEL org.opencontainers.image.title="cicada" \
org.opencontainers.image.authors="mebtte<hi@mebtte.com>" \
org.opencontainers.image.authors="mebtte<i@mebtte.com>" \
org.opencontainers.image.url="https://github.com/mebtte/cicada"
8 changes: 4 additions & 4 deletions apps/cli/src/commands/import_music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let ignored = 0;

/**
* 检查音乐是否已存在
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
async function checkMusicExist({
singers,
Expand Down Expand Up @@ -90,7 +90,7 @@ async function importFile(

/**
* 检查文件类型
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const ft = await fileType.fromFile(filepath);
const { acceptTypes } = ASSET_TYPE_MAP[AssetType.MUSIC];
Expand Down Expand Up @@ -207,7 +207,7 @@ async function importDirectory(
) {
/**
* 过滤隐藏文件
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const files = (await fs.readdir(directory)).filter((f) => !f.startsWith('.'));
for (const file of files) {
Expand Down Expand Up @@ -247,7 +247,7 @@ async function importMusic({

/**
* 检查 uid 是否存在
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const user = await getUserById(uid, [UserProperty.ID]);
if (!user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default async (ctx: Context) => {
/**
* 1. 删除数据库相关记录, 注意外键依赖顺序
* 2. 转移所有权
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const musicbillList = await getUserMusicbillList(id, [MusicbillProperty.ID]);
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) => {
name.trim() !== name ||
typeof singerIds !== 'string' ||
!singerIds.length ||
// @ts-expect-error
// @ts-expect-error: known type
!MUSIC_TYPES.includes(type) ||
typeof asset !== 'string'
) {
Expand All @@ -54,7 +54,7 @@ export default async (ctx: Context) => {

/**
* 0 表示无限制
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
if (ctx.user.createMusicMaxAmountPerDay !== 0) {
const now = day();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async (ctx: Context) => {

/**
* 0 表示无限制
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
if (ctx.user.musicbillMaxAmount !== 0) {
const musicbillList = await getUserMusicbillList(ctx.user.id, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Context } from '../constants';
/**
* 所有者可以删除任何人
* 共享者只能删除自己
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
export default async (ctx: Context) => {
const { musicbillId, userId } = ctx.query as {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async (ctx: Context) => {
* 1. 乐单是否存在
* 2. 是否乐单创建者
* 3. 是否拥有共享乐单
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const musicbill = await getDB().get<
Pick<
Expand Down Expand Up @@ -130,13 +130,11 @@ export default async (ctx: Context) => {
[id],
);

const musicIdMapSingers: {
[key: string]: {
const musicIdMapSingers: Record<string, {
id: string;
name: string;
aliases: string[];
}[];
} = {};
}[]> = {};
if (musicList.length) {
const allSingerList = await getSingerListInMusicIds(
Array.from(new Set(musicList.map((m) => m.id))),
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/start_server/api_app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ router.delete('/2fa', disable2FA); // disable 2FA

/**
* 管理员
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
router.post('/admin/user', adminAuthorize, parseBody, adminCreateUser); // 创建用户
router.put('/admin/user', adminAuthorize, parseBody, adminUpdateUser); // 更新用户
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function getCover(
/**
* 如果图片本身尺寸小于需要的尺寸
* 直接写入缓存
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
if (cover.bitmap.width > sizeNumber) {
await new Promise<void>((resolve, reject) =>
Expand All @@ -57,13 +57,13 @@ async function getCover(
await fsPromises.writeFile(cachePath, fs.createReadStream(assetPath));
}
}
return send(ctx, cacheName, {
return await send(ctx, cacheName, {
immutable: true,
root: getCacheDirectory(),
});
}

return send(ctx, asset, {
return await send(ctx, asset, {
immutable: true,
root: getAssetDirectory(type),
});
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/start_server/base_app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.post('/login_with_2fa', parseBody, loginWith2FA);
* 上传音乐播放记录
* 由于使用 navigator.sendBeacon
* 无法设置 http header, 需要特殊处理鉴权
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
router.post('/music_play_record', parseBody, createMusicPlayRecord);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const isSquare = async (buffer: Buffer) => {
const image = await jimp.read(buffer);
/**
* 允许一定的误差
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
return Math.abs(image.bitmap.width - image.bitmap.height) < 5;
};
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/start_server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async ({

/**
* 当 navigator.sendBeacon 格式是 json 时必须
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
credentials: true,
}),
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/commands/start_server/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function mkdirIfNotExist(dir: string) {
export default async () => {
/**
* create directory
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const directories = [
getConfig().data,
Expand All @@ -73,7 +73,7 @@ export default async () => {

/**
* initialize or verify data version
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
if (fs.existsSync(getDataVersionPath())) {
const dataVersion = Number(
Expand All @@ -95,7 +95,7 @@ export default async () => {

/**
* initialize database
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
if (
!fs.existsSync(getDBFilePath()) ||
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/commands/upgrade_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function addUserPassword() {

/**
* make user.password not null
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const tmpTableName = 'user_tmp';
await getDB().run(
Expand Down
8 changes: 4 additions & 4 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const program = new Command()

/**
* 启动服务
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
program
.command('start')
Expand Down Expand Up @@ -62,7 +62,7 @@ program

/**
* 数据升级
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
program
.command('upgrade data')
Expand All @@ -80,7 +80,7 @@ program

/**
* 数据修复
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
program
.command('fix-data')
Expand All @@ -98,7 +98,7 @@ program

/**
* 导入音乐
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
program
.command('import')
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/platform/captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function verify({
/**
* 无论验证成功与否
* 都需要记录已使用
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
getDB()
.run(
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/utils/db.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* API referrence: https://github.com/TryGhost/node-sqlite3/wiki/API
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
import * as sqlite3 from 'sqlite3';

export enum EventType {
PROFILE = 'profile',
}
type EventTypeMapListener = {
interface EventTypeMapListener {
[EventType.PROFILE]: (sql: string, ms: number) => void;
};
}

class DB {
db: sqlite3.Database;
Expand Down
Binary file removed apps/pwa/src/asset/default_singer_avatar.jpeg
Binary file not shown.
1 change: 1 addition & 0 deletions apps/pwa/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const Style = styled.button<{
height: ${ComponentSize.NORMAL}px;
padding: 0 15px;
white-space: nowrap;
border-radius: ${CSSVariable.BORDER_RADIUS_NORMAL};
font-size: ${CSSVariable.TEXT_SIZE_NORMAL};
cursor: pointer;
Expand Down
2 changes: 1 addition & 1 deletion apps/pwa/src/components/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Body = styled(animated.div)`

/**
* 弹窗
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const Dialog = ({
open,
Expand Down
2 changes: 1 addition & 1 deletion apps/pwa/src/components/empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Style = styled.div`

/**
* 空数据
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
function Empty({
/** 描述 */
Expand Down
2 changes: 1 addition & 1 deletion apps/pwa/src/components/error_boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import logger from '@/utils/logger';

/**
* 错误边界
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
class ErrorBoundary extends React.PureComponent<
React.PropsWithChildren<{
Expand Down
2 changes: 1 addition & 1 deletion apps/pwa/src/components/error_card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Style = styled.div`

/**
* 错误卡片
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
function ErrorCard({
errorMessage,
Expand Down
2 changes: 1 addition & 1 deletion apps/pwa/src/components/page_container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';

/**
* 根路由容器
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const RouteContainer = styled.div`
${absoluteFullSize}
Expand Down
2 changes: 1 addition & 1 deletion apps/pwa/src/components/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const Body = styled(animated.div)`

/**
* 弹出框
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
const Popup = ({
open,
Expand Down
2 changes: 1 addition & 1 deletion apps/pwa/src/components/spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Style = styled.div`

/**
* 加载器
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
function Spinner({
size = ComponentSize.SMALL,
Expand Down
1 change: 1 addition & 0 deletions apps/pwa/src/definition.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable no-underscore-dangle,no-undef */
declare global {
// eslint-disable-next-line @typescript-eslint/naming-convention
const __DEFINE__: {
VERSION: string;

Expand Down
10 changes: 5 additions & 5 deletions apps/pwa/src/global_states/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import XState from '@/utils/x_state';
import logger from '@/utils/logger';
import storage, { Key } from '@/storage';
import { Server, ServerState } from '@/constants/server';
import { type Server, type ServerState } from '@/constants/server';
import globalEventemitter, { EventType } from '@/platform/global_eventemitter';
import getMetadata from '@/server/base/get_metadata';
import getProfile from '@/server/api/get_profile';
import definition from '@/definition';
import { BETA_VERSION_START } from '#/constants';

Expand Down Expand Up @@ -34,7 +32,8 @@ server.onChange((ss) => {
window.setInterval(() => {
const selectedServer = getSelectedServer(server.get());
if (selectedServer) {
getMetadata(selectedServer.origin)
import('@/server/base/get_metadata')
.then(({ default: getMetadata }) => getMetadata(selectedServer.origin))
.then((data) => {
if (
!definition.DEVELOPMENT &&
Expand All @@ -43,7 +42,7 @@ window.setInterval(() => {
) {
/**
* @todo 不兼容提示
* @author mebtte<hi@mebtte.com>
* @author mebtte<i@mebtte.com>
*/
}

Expand Down Expand Up @@ -98,6 +97,7 @@ export async function reloadUser() {
if (selectedServer) {
const user = getSelectedUser(selectedServer);
if (user) {
const { default: getProfile } = await import('@/server/api/get_profile');
const profile = await getProfile(user.token);
server.set((ss) => ({
...ss,
Expand Down
Loading

0 comments on commit 678bec0

Please sign in to comment.