@@ -8,8 +8,6 @@ import { UserService } from '../user.service'
8
8
// TODO: need better cache impl
9
9
let siteCategoryCache : SiteCat [ ] | null = null
10
10
11
- const DEFAULT_ORDER = 999999
12
-
13
11
async function getAuthedPostCatReq ( ) {
14
12
const token = await AuthManager . acquireToken ( )
15
13
// TODO: need better solution
@@ -24,54 +22,7 @@ export namespace PostCatService {
24
22
const resp = await req . getAll ( )
25
23
const { categories } = < { categories : PostCat [ ] } > JSON . parse ( resp )
26
24
if ( categories == null ) return [ ]
27
- return categories . map ( x => Object . assign ( new PostCat ( ) , x ) )
28
- } catch ( e ) {
29
- if ( await UserService . hasBlog ( ) ) void Alert . err ( `查询随笔分类失败: ${ < string > e } ` )
30
- throw e
31
- }
32
- }
33
-
34
- export async function getFlatAll ( ) {
35
- const categories = await getAll ( )
36
- if ( categories == null || categories . length === 0 ) return [ ]
37
-
38
- const flat = [ ]
39
- const queue = categories
40
- while ( queue . length > 0 ) {
41
- const current = queue . pop ( )
42
- if ( current == null ) continue
43
- flat . push ( current )
44
- if ( current . children != null ) for ( const child of current . children ) queue . unshift ( child )
45
- }
46
-
47
- return flat . sort ( ( x , y ) => {
48
- const order1 = x . order ?? DEFAULT_ORDER
49
- const order2 = y . order ?? DEFAULT_ORDER
50
- if ( order1 > order2 ) return 1
51
- else if ( order1 < order2 ) return - 1
52
- else return x . title . localeCompare ( y . title )
53
- } )
54
- }
55
-
56
- export async function getOne ( categoryId : number ) {
57
- const req = await getAuthedPostCatReq ( )
58
- try {
59
- const resp = await req . getOne ( categoryId )
60
- const { parent } = < { parent : PostCat | null } > JSON . parse ( resp )
61
- return Object . assign ( new PostCat ( ) , parent )
62
- } catch ( e ) {
63
- if ( await UserService . hasBlog ( ) ) void Alert . err ( `查询随笔分类失败: ${ < string > e } ` )
64
- throw e
65
- }
66
- }
67
-
68
- export async function getAllUnder ( parentId : number ) {
69
- const req = await getAuthedPostCatReq ( )
70
- try {
71
- const resp = await req . getOne ( parentId )
72
- const { categories } = < { categories : PostCat [ ] } > JSON . parse ( resp )
73
- if ( categories == null ) return [ ]
74
- return categories . map ( x => Object . assign ( new PostCat ( ) , x ) )
25
+ return categories
75
26
} catch ( e ) {
76
27
if ( await UserService . hasBlog ( ) ) void Alert . err ( `查询随笔分类失败: ${ < string > e } ` )
77
28
throw e
0 commit comments