Separate serve lib
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const basePathname = path.join(process.cwd(), 'public/data')
|
||||
|
||||
export function resolvePathname(pathname: string) {
|
||||
return path.join(basePathname, pathname)
|
||||
}
|
||||
|
||||
export function readdirSync(pathname: string) {
|
||||
const fileList = fs.readdirSync(resolvePathname(pathname))
|
||||
|
||||
return fileList
|
||||
}
|
||||
|
||||
export function readFileSync(pathname: string) {
|
||||
return fs.readFileSync(resolvePathname(pathname))
|
||||
}
|
||||
|
||||
export function readJsonFileSync(pathname: string) {
|
||||
const rawData = readFileSync(pathname).toString()
|
||||
|
||||
return JSON.parse(rawData)
|
||||
}
|
||||
@@ -1,31 +1,6 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { readdirSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface BattlesuitSkill {
|
||||
name: string
|
||||
description: string
|
||||
requiredRank: string
|
||||
}
|
||||
export interface BattlesuitSkillGroup {
|
||||
core: BattlesuitSkill
|
||||
subskills: BattlesuitSkill[]
|
||||
}
|
||||
|
||||
export interface BattlesuitData {
|
||||
id: string
|
||||
version?: string
|
||||
name: string
|
||||
type: string
|
||||
valkyrie: string
|
||||
strengths: string[]
|
||||
leader: BattlesuitSkillGroup
|
||||
special: BattlesuitSkillGroup
|
||||
evasion: BattlesuitSkillGroup
|
||||
passive: BattlesuitSkillGroup
|
||||
ultimate: BattlesuitSkillGroup
|
||||
basic: BattlesuitSkillGroup
|
||||
sp?: BattlesuitSkillGroup
|
||||
}
|
||||
import { BattlesuitData } from '../../../lib/honkai3rd/battlesuits'
|
||||
|
||||
const battlesuitsFileNameList = readdirSync('honkai3rd/battlesuits')
|
||||
const battlesuitDataList = battlesuitsFileNameList
|
||||
|
||||
@@ -1,21 +1,6 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { readdirSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface ElfSkill {
|
||||
type: 'passive' | 'basic' | 'ultimate' | 'team'
|
||||
name: string
|
||||
requiredRank: number
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface ElfData {
|
||||
id: string
|
||||
name: string
|
||||
baseRank: number
|
||||
strengths: string[]
|
||||
skillRows: [ElfSkill[], ElfSkill[], ElfSkill[], ElfSkill[]]
|
||||
version: string
|
||||
}
|
||||
import { ElfData } from '../../../lib/honkai3rd/elfs'
|
||||
|
||||
const elfFileNameList = readdirSync('honkai3rd/elfs')
|
||||
const elfDataList = elfFileNameList
|
||||
|
||||
@@ -1,34 +1,6 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { readdirSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface StigmataSkill {
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface StigmataData {
|
||||
id: string
|
||||
name: string
|
||||
skill: StigmataSkill
|
||||
ttk: number
|
||||
def: number
|
||||
crt: number
|
||||
set?: string
|
||||
type: 'top' | 'mid' | 'bot'
|
||||
hp: number
|
||||
rarity: 3 | 4 | 5
|
||||
version?: string
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export interface StigmataSet {
|
||||
id: string
|
||||
name: string
|
||||
altName: string
|
||||
twoSetSkill: StigmataSkill
|
||||
threeSetSkill: StigmataSkill
|
||||
version?: string
|
||||
}
|
||||
import { StigmataData, StigmataSet } from '../../../lib/honkai3rd/stigmata'
|
||||
|
||||
const stigmataDataFileNameList = readdirSync('honkai3rd/stigmata')
|
||||
const stigmataList = stigmataDataFileNameList
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
|
||||
export interface SupplyEventData {
|
||||
id: string
|
||||
verified: boolean
|
||||
track: number
|
||||
name: string
|
||||
type: string
|
||||
token: string
|
||||
featured: {
|
||||
type: string
|
||||
id: string
|
||||
}[]
|
||||
extra: string[]
|
||||
version: number
|
||||
duration: [string, string]
|
||||
guarantees: {
|
||||
count: number
|
||||
recurring: boolean
|
||||
rewards: { type: string; id: string; amount: number | [number, number] }[]
|
||||
}[]
|
||||
mileages: {
|
||||
count: number
|
||||
rewardOptions: {
|
||||
type: string
|
||||
id: string
|
||||
amount: number
|
||||
}[]
|
||||
}[]
|
||||
drops: {
|
||||
type: string
|
||||
id: string
|
||||
rate: number
|
||||
amount: number | [number, number]
|
||||
}[]
|
||||
}
|
||||
|
||||
export function listSupplyEventsByVersion(version: string) {
|
||||
const supplyEventsDirectoryPathname = `honkai3rd/versions/${version}/supply-events`
|
||||
|
||||
const supplyEventFileNameList = readdirSync(supplyEventsDirectoryPathname)
|
||||
const supplyEventList = supplyEventFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = `${supplyEventsDirectoryPathname}/` + fileName
|
||||
const data = readJsonFileSync(filePathname)
|
||||
|
||||
return { ...data, id: fileName.replace(/\.json/, '') } as SupplyEventData
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return -a.id.localeCompare(b.id)
|
||||
})
|
||||
|
||||
return supplyEventList
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { SupplyEventData } from '../../../lib/honkai3rd/supplyEvents'
|
||||
import { readdirSync, readJsonFileSync } from '../fs'
|
||||
|
||||
export function listSupplyEventsByVersion(version: string) {
|
||||
const supplyEventsDirectoryPathname = `honkai3rd/versions/${version}/supply-events`
|
||||
|
||||
const supplyEventFileNameList = readdirSync(supplyEventsDirectoryPathname)
|
||||
const supplyEventList = supplyEventFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = `${supplyEventsDirectoryPathname}/` + fileName
|
||||
const data = readJsonFileSync(filePathname)
|
||||
|
||||
return { ...data, id: fileName.replace(/\.json/, '') } as SupplyEventData
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return -a.id.localeCompare(b.id)
|
||||
})
|
||||
|
||||
return supplyEventList
|
||||
}
|
||||
@@ -1,18 +1,7 @@
|
||||
import { format } from 'date-fns'
|
||||
import { readdirSync, readFileSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { readdirSync, readFileSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface VersionData {
|
||||
version: string
|
||||
previousVersion?: string
|
||||
nextVersion?: string
|
||||
name: string
|
||||
duration: [string, string]
|
||||
verified: boolean
|
||||
newBattlesuits: string[]
|
||||
newWeapons: string[]
|
||||
description: string
|
||||
}
|
||||
import { VersionData } from '../../../lib/honkai3rd/versions'
|
||||
|
||||
const versionDirectoryList = readdirSync('honkai3rd/versions')
|
||||
|
||||
|
||||
@@ -1,30 +1,6 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { readdirSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface WeaponSkill {
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface WeaponData {
|
||||
id: string
|
||||
name: string
|
||||
atk: number
|
||||
crt: number
|
||||
category:
|
||||
| 'pistol'
|
||||
| 'cannon'
|
||||
| 'katana'
|
||||
| 'cross'
|
||||
| 'greatsword'
|
||||
| 'scythe'
|
||||
| 'lance'
|
||||
| 'gauntlet'
|
||||
| 'bow'
|
||||
rarity: number
|
||||
skills: WeaponSkill[]
|
||||
version?: string
|
||||
}
|
||||
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
||||
|
||||
const weaponsFileNameList = readdirSync('honkai3rd/weapons')
|
||||
const weaponDataList = weaponsFileNameList
|
||||
|
||||
Reference in New Issue
Block a user