Skip to content

Commit 6fbfd20

Browse files
committed
refactor: to ts
1 parent 50e62b0 commit 6fbfd20

File tree

6 files changed

+133
-7
lines changed

6 files changed

+133
-7
lines changed

get-types.mjs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!env zx
2+
3+
fetch(
4+
'https://fastly.jsdelivr.net/gh/mx-space/assets@master/types/type.declare.ts',
5+
)
6+
.then((res) => res.text())
7+
.then((text) => {
8+
fs.writeFileSync('./global.d.ts', text, { encoding: 'utf8' })
9+
})

global.d.ts

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* eslint-disable @typescript-eslint/no-empty-interface */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
// THIS FILE FOR MONACO EDITOR CODE COMPLETION
4+
5+
declare interface FunctionContextResponse {
6+
throws(code: number, message: any): void
7+
type(type: string): FunctionContextResponse
8+
status(code: number, statusMessage?: string): FunctionContextResponse
9+
send(data: any): void
10+
}
11+
declare interface FunctionContextRequest {
12+
query: Record<string, string>
13+
headers: Record<string, string>
14+
params: Record<string, string>
15+
}
16+
17+
declare interface FastifyRequest {
18+
[k: string]: any
19+
}
20+
declare interface Context extends FunctionContextResponse {}
21+
declare interface Context extends FunctionContextRequest {}
22+
declare interface Context {
23+
req: FunctionContextRequest & FastifyRequest
24+
res: FunctionContextResponse
25+
26+
model: SnippetModel
27+
document: SnippetModel & { [key: string]: any }
28+
getMaster: () => Promise<UserModel>
29+
30+
storage: IStorage
31+
32+
name: string
33+
reference: string
34+
35+
writeAsset: (path: string, data: any, options: any) => void
36+
readAsset: (path: string, options: any) => void
37+
}
38+
39+
declare interface IStorage {
40+
db: any
41+
cache: {
42+
get(key: string): Promise<string>
43+
set(key: string, value: string | object): Promise<string>
44+
dek(key: string): Promise<string>
45+
}
46+
}
47+
48+
declare const __dirname: string
49+
declare const __filename: ''
50+
51+
declare class Buffer {
52+
constructor(...args: any[]): Buffer
53+
from(...args: any[]): Buffer
54+
[x: string]: any
55+
}
56+
57+
declare const console: Console
58+
59+
declare const logger: Console
60+
61+
declare const process: {
62+
env: Record<string, string>
63+
nextTick: (func: Function) => any
64+
}
65+
declare const context: Context
66+
67+
declare enum SnippetType {
68+
JSON = 'json',
69+
Function = 'function',
70+
Text = 'text',
71+
YAML = 'yaml',
72+
}
73+
74+
declare interface SnippetModel extends BaseModel {
75+
type: SnippetType
76+
private: boolean
77+
raw: string
78+
name: string
79+
reference: string
80+
comment?: string
81+
metatype?: string
82+
}
83+
84+
declare class BaseModel {
85+
created?: Date
86+
id?: string
87+
}
88+
89+
declare class UserModel {
90+
username: string
91+
92+
name: string
93+
94+
introduce?: string
95+
96+
avatar?: string
97+
98+
mail?: string
99+
100+
url?: string
101+
102+
lastLoginTime?: Date
103+
104+
lastLoginIp?: string
105+
106+
socialIds?: any
107+
}
108+
declare function require(id: string, useCache?: boolean): Promise<any>

kami/functions/bangumi.js renamed to kami/functions/bangumi.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import extra from '@mx-space/extra'
12
async function handler() {
2-
const extra = await require('@mx-space/extra')
33
const { BiliClient } = extra
44
const bl = await context.getMaster().then((user) => user.socialIds.bilibili)
55
const client = new BiliClient(parseInt(bl || uid))
6-
const bangumi = await client.getFavoriteBangumi(parseInt(len))
6+
const bangumi = await client.getFavoriteBangumi(parseInt(len.toString()))
77
return bangumi
88
}
99
// 如果社交平台 ID 录入中有哔哩哔哩 ID 可不填,留空

kami/functions/netease.js renamed to kami/functions/netease.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
async function handler(ctx, require) {
2-
const extra = await require('@mx-space/extra')
1+
import extra from '@mx-space/extra'
2+
3+
async function handler() {
34
const { NeteaseMusic } = extra
45

56
const client = new NeteaseMusic(phone, password)

kami/functions/song.js renamed to kami/functions/song.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
async function handler(ctx, require) {
2-
const { NeteaseCloudMusicApi } = await require('@mx-space/extra')
1+
import { NeteaseCloudMusicApi } from '@mx-space/extra'
2+
3+
async function handler() {
34
const { song_url } = NeteaseCloudMusicApi
4-
const id = ctx.req.query.id
5+
const id = context.req.query.id
56
if (!id) {
67
return { message: 'id must be not empty stringnumber' }
78
}

tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2017",
4+
"allowJs": true,
5+
"noEmit": true
6+
}
7+
}

0 commit comments

Comments
 (0)