50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { API_BASE_URL } from '~/CONSTANT'
|
|
|
|
const saberPaths = ref<string[]>([])
|
|
const currentSaberDays = ref<string>('')
|
|
|
|
async function refreshPath() {
|
|
if (saberPaths.value.length)
|
|
return
|
|
const resp = await baseFetch<string[]>(`${API_BASE_URL}/saber/metadata`).json()
|
|
const data = resp.data.value
|
|
saberPaths.value = data!
|
|
}
|
|
|
|
async function refreshCurrentSaberDays(path: string) {
|
|
const resp = await baseFetch<string>(`${API_BASE_URL}/saber/metadata/list_days?path=${path}`).json()
|
|
const data = resp.data.value
|
|
currentSaberDays.value = data!
|
|
}
|
|
function renderPath(path: string) {
|
|
const yearPattern = /\/data\/(\d{4})/
|
|
const year = path.match(yearPattern)?.[1]
|
|
const monthPattern = /Temp_O3_(.*)(\d{4})/
|
|
const month_mapping = {
|
|
January: '01月',
|
|
February: '02月',
|
|
March: '03月',
|
|
April: '04月',
|
|
May: '05月',
|
|
June: '06月',
|
|
July: '07月',
|
|
August: '08月',
|
|
September: '09月',
|
|
October: '10月',
|
|
November: '11月',
|
|
December: '12月',
|
|
} as const
|
|
const month = path.match(monthPattern)?.[1] as keyof typeof month_mapping
|
|
return `${year}年${month_mapping[month]}`
|
|
}
|
|
|
|
function parseDayOfYear(dateString: string): Date {
|
|
const year = Number.parseInt(dateString.substring(0, 4))
|
|
const dayOfYear = Number.parseInt(dateString.substring(4)) - 1 // subtract 1 because JS dates are 0-based
|
|
const date = new Date(year, 0) // Start with January 1st of the year
|
|
date.setDate(dayOfYear + 1) // Add the days
|
|
return date
|
|
}
|
|
|
|
export { currentSaberDays, parseDayOfYear, refreshCurrentSaberDays, refreshPath, renderPath, saberPaths }
|