このコミットが含まれているのは:
@@ -0,0 +1,44 @@
|
||||
import { apiGet } from '@/lib/api'
|
||||
|
||||
import type { LocaleCode } from '@/lib/locales'
|
||||
import type { PostVersion, TagVersion } from '@/types'
|
||||
|
||||
export type CountsResource = 'posts' | 'tags'
|
||||
export type CountsResult = {
|
||||
count: number
|
||||
page: number
|
||||
limit: number
|
||||
groupCount?: number
|
||||
groups?: { key: string | number | null; name: string | null; count: number }[]
|
||||
versions?: (PostVersion | TagVersion)[] }
|
||||
|
||||
export const countColumns = {
|
||||
created_at: '変更日時', resource_id: 'ID', version_no: '版番号',
|
||||
event_type: '操作種別', user: '操作者', title: '投稿タイトル', url: '投稿 URL',
|
||||
tags: '記載タグ', added_tags: '追加されたタグ', removed_tags: '削除されたタグ',
|
||||
name: 'タグ名', category: 'カテゴリ', aliases: '別名', parents: '上位タグ',
|
||||
deprecated: '廃止状態' }
|
||||
|
||||
export type CountColumn = keyof typeof countColumns
|
||||
|
||||
|
||||
export const columnsForCounts = (resource: CountsResource): CountColumn[] => [
|
||||
'created_at', 'resource_id', 'version_no', 'event_type', 'user',
|
||||
...(resource === 'posts'
|
||||
? ['title', 'url', 'tags', 'added_tags', 'removed_tags'] as const
|
||||
: ['name', 'category', 'aliases', 'parents', 'deprecated'] as const)]
|
||||
|
||||
|
||||
export const fetchCounts = (
|
||||
resource: CountsResource,
|
||||
params: URLSearchParams,
|
||||
locale: LocaleCode,
|
||||
): Promise<CountsResult> => apiGet (`/counts/${resource}`, {
|
||||
locale, params: Object.fromEntries (params) })
|
||||
|
||||
|
||||
export const countsCSV = (rows: string[][]): string =>
|
||||
'\uFEFF' + rows.map (row => row.map (value => {
|
||||
const safe = /^[=+@\-\t\r]/.test (value) ? `'${value}` : value
|
||||
return `"${safe.replaceAll ('"', '""')}"`
|
||||
}).join (',')).join ('\r\n')
|
||||
新しいイシューから参照
ユーザーをブロックする