Skip to content

Commit

Permalink
feat: setup prsima,database and koajs
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Jun 8, 2024
0 parents commit 82fa140
Show file tree
Hide file tree
Showing 26 changed files with 5,252 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"root": true,
"env": {
"es2024": true
},
"extends": ["airbnb-base", "prettier", "typescript"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"rules": {
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": 0,
"import/extensions": 0,
"no-use-before-define": 0,
"no-unused-vars": 0,
"no-shadow": 0,
"no-redeclare": 0
},
"ignorePatterns": ["*.js", "*.d.ts"]
}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
dist
lib
.husky/_

.vscode/*
.vs/*
!.vscode/extensions.json

*.tgz
*.log
tsconfig.tsbuildinfo
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"printWidth": 120,
"trailingComma": "none"
}
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# moehub

Your anime character collection gallery, easily build, freely share.

## Stacks

- Frontend: React, tailwind-css
- Backend: Node.js, Koa.js, Prisma
- Database: Mysql
- CI/CD: Github Actions
- Code Style: ESLint, Prettier
- Version Control: Git, GitHub
- Project Management: pnpm workspace
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@moehub/root",
"description": "Anime character collection gallery",
"version": "1.0.0",
"private": true,
"license": "GPL-3.0",
"author": "Romi <[email protected]>",
"scripts": {
"build": "tsup",
"dev": "nodemon --watch",
"lint": "eslint \"packages/*/src/*.ts\" --fix",
"format": "prettier --config .prettierrc \"packages/*/src/*.ts\" --write",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
},
"devDependencies": {
"conventional-changelog-cli": "^4.1.0",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-typescript": "^3.0.0",
"nodemon": "^3.1.3",
"prettier": "^3.3.0",
"tsup": "^8.1.0",
"tsx": "^4.11.2",
"typescript": "^5.4.5"
},
"packageManager": "[email protected]+",
"engines": {
"node": ">=17.9.0"
},
"nodemonConfig": {
"exec": "tsx packages/core/src",
"ext": "ts"
}
}
3 changes: 3 additions & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
39 changes: 39 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@moehub/core",
"version": "1.0.0",
"description": "Your anime character collection gallery, easily build, freely share.",
"main": "lib/index.js",
"license": "GPL-3.0",
"author": "Romi <[email protected]>",
"keywords": [
"anime",
"character",
"gallery",
"share",
"acg",
"server",
"bot",
"web",
"back-end"
],
"bugs": {
"url": "https://github.com/biyuehu/moehub/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/biyuehu/moehub.git"
},
"dependencies": {
"@kotori-bot/logger": "^1.3.1",
"@prisma/client": "^5.15.0",
"koa": "^2.15.3",
"koa-bodyparser": "^4.4.1",
"koa-router": "^12.0.1"
},
"devDependencies": {
"@types/koa": "^2.15.0",
"@types/koa-bodyparser": "^4.3.12",
"@types/koa-router": "^7.4.8",
"prisma": "5.15.0"
}
}
100 changes: 100 additions & 0 deletions packages/core/prisma/migrations/20240608133252_y/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
-- CreateTable
CREATE TABLE `Character` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`romanized` VARCHAR(191) NOT NULL,
`gender` ENUM('MALE', 'FEMALE', 'OTHER') NOT NULL,
`alias` VARCHAR(191) NULL,
`age` INTEGER NULL,
`images` VARCHAR(191) NULL,
`url` VARCHAR(191) NULL,
`description` VARCHAR(191) NULL,
`comment` VARCHAR(191) NULL,
`hitokoto` VARCHAR(191) NULL,
`birthday` DATETIME(3) NULL,
`actorId` INTEGER NULL,
`seriesId` INTEGER NOT NULL,
`hairColor` VARCHAR(191) NULL,
`eyeColor` VARCHAR(191) NULL,
`bloodType` ENUM('A', 'B', 'AB', 'O') NULL,
`height` INTEGER NULL,
`bust` INTEGER NULL,
`waist` INTEGER NULL,
`hip` VARCHAR(191) NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

UNIQUE INDEX `Character_id_name_key`(`id`, `name`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Actor` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,

UNIQUE INDEX `Actor_id_name_key`(`id`, `name`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Series` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`title` VARCHAR(191) NOT NULL,
`genre` ENUM('ANIME', 'COMIC', 'GALGAME', 'GAME', 'NOVEL', 'OTHER') NOT NULL,

UNIQUE INDEX `Series_id_title_key`(`id`, `title`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Tag` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,

UNIQUE INDEX `Tag_id_name_key`(`id`, `name`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CharacterWithTag` (
`characterId` INTEGER NOT NULL,
`tagId` INTEGER NOT NULL,

PRIMARY KEY (`characterId`, `tagId`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Collection` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`description` VARCHAR(191) NULL,

UNIQUE INDEX `Collection_id_name_key`(`id`, `name`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CharacterWithCollection` (
`characterId` INTEGER NOT NULL,
`collectionId` INTEGER NOT NULL,

PRIMARY KEY (`characterId`, `collectionId`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Character` ADD CONSTRAINT `Character_actorId_fkey` FOREIGN KEY (`actorId`) REFERENCES `Actor`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Character` ADD CONSTRAINT `Character_seriesId_fkey` FOREIGN KEY (`seriesId`) REFERENCES `Series`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CharacterWithTag` ADD CONSTRAINT `CharacterWithTag_characterId_fkey` FOREIGN KEY (`characterId`) REFERENCES `Character`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CharacterWithTag` ADD CONSTRAINT `CharacterWithTag_tagId_fkey` FOREIGN KEY (`tagId`) REFERENCES `Tag`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CharacterWithCollection` ADD CONSTRAINT `CharacterWithCollection_characterId_fkey` FOREIGN KEY (`characterId`) REFERENCES `Character`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CharacterWithCollection` ADD CONSTRAINT `CharacterWithCollection_collectionId_fkey` FOREIGN KEY (`collectionId`) REFERENCES `Collection`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions packages/core/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "mysql"
124 changes: 124 additions & 0 deletions packages/core/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}

enum Gender {
MALE
FEMALE
OTHER
}

enum SeriesGenre {
ANIME
COMIC
GALGAME
GAME
NOVEL
OTHER
}

enum bloodType {
A
B
AB
O
}

model Character {
id Int @id @default(autoincrement()) // 唯一标识符
// 必要数据
name String // 角色名(日语原名)
romanized String // 角色名罗马音
gender Gender // 角色性别
// 基本数据
alias String? // 角色中文名、昵称、别名(字符串数组)
age Int? // 角色年龄
images String? // 角色相关图片(字符串数组)
url String? // 角色相关链接(字符串数组)
description String? // 角色描述
comment String? // 角色个人评论
hitokoto String? // 角色一言
birthday DateTime? // 角色生日
actor Actor? @relation(fields: [actorId], references: [id]) // 角色声优
actorId Int?
// 关联数据
series Series @relation(fields: [seriesId], references: [id]) // 角色所属系列作品
seriesId Int
collections CharacterWithCollection[] // 角色所属收藏夹
tags CharacterWithTag[] // 角色萌点
// 额外数据
hairColor String? // 角色发色
eyeColor String? // 角色瞳色
bloodType bloodType? // 角色血型
height Int? // 角色身高
bust Int? // 角色胸围
waist Int? // 角色腰围
hip String? // 角色臀围
createdAt DateTime @default(now())
@@unique([id, name])
}

model Actor {
id Int @id @default(autoincrement())
name String // 声优名
characters Character[]
@@unique([id, name])
}

model Series {
id Int @id @default(autoincrement())
title String // 作品名字
genre SeriesGenre // 作品类型,如动漫、漫画、视觉小说、游戏、轻小说等
characters Character[]
@@unique([id, title])
}

model Tag {
id Int @id @default(autoincrement())
name String // 标签名
characters CharacterWithTag[]
@@unique([id, name])
}

model CharacterWithTag {
character Character @relation(fields: [characterId], references: [id])
characterId Int
tag Tag @relation(fields: [tagId], references: [id])
tagId Int
@@id([characterId, tagId])
}

model Collection {
id Int @id @default(autoincrement())
name String // 收藏夹名
description String? // 收藏夹描述
characters CharacterWithCollection[]
@@unique([id, name])
}

model CharacterWithCollection {
character Character @relation(fields: [characterId], references: [id])
characterId Int
collection Collection @relation(fields: [collectionId], references: [id])
collectionId Int
@@id([characterId, collectionId])
}
9 changes: 9 additions & 0 deletions packages/core/src/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import router from '../router';

const app = new Koa();

app.use(bodyParser()).use(router.routes()).use(router.allowedMethods());

export default app;
3 changes: 3 additions & 0 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
port: 5000,
};
21 changes: 21 additions & 0 deletions packages/core/src/controller/character.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Context } from 'koa';
import model from '../model';

class CharacterController {
static get(ctx: Context) {
const { id } = ctx.params;
if (!id) return model.character.findMany();
return model.character.findUnique({ where: { id } });
}

static post(ctx: Context) {
const data = ctx.request.body;
return model.character.create(data as any);
}

static put(ctx: Context) {}

static delete(ctx: Context) {}
}

export default CharacterController;
Loading

0 comments on commit 82fa140

Please sign in to comment.