forked from userbot000/otzaria-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api-direct.js
More file actions
53 lines (42 loc) ยท 1.71 KB
/
Copy pathtest-api-direct.js
File metadata and controls
53 lines (42 loc) ยท 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ืืืืงื ืืฉืืจื ืฉื ื-API
import { listFiles, readJSON } from './src/lib/storage.js'
async function testAPI() {
try {
console.log('๐ ืงืืจื ืจืฉืืืช ืงืืฆืื...\n')
const files = await listFiles('data/pages/')
console.log(`๐ฆ ื ืืฆืื ${files.length} ืงืืฆืื`)
for (const file of files) {
console.log(`\n๐ File: ${file.pathname}`)
console.log(` URL: ${file.url}`)
console.log(` Size: ${file.size}`)
}
console.log('\n\n๐ ืื ืกื ืืงืจืื ืืช ืืกืคืจ "ืืืืช ืืขืช"...\n')
const pages = await readJSON('data/pages/ืืืืช ืืขืช.json')
if (!pages) {
console.log('โ ืื ืืฆืืืชื ืืงืจืื ืืช ืืงืืืฅ!')
} else if (!Array.isArray(pages)) {
console.log('โ ืื ืชืื ืื ืื ืืขืจื!')
console.log('ืกืื:', typeof pages)
} else {
console.log(`โ
ืืฆืืืชื ืืงืจืื ${pages.length} ืขืืืืื`)
console.log(` ืืืฉืืื: ${pages.filter(p => p.status === 'completed').length}`)
console.log(` ืชืืื ื ืจืืฉืื ื: ${pages[0]?.thumbnail}`)
// ืืืื ื ืืืืง ืืช ืืืื ื ืฉื ืืกืคืจ
const bookName = 'ืืืืช ืืขืช'
const totalPages = pages.length
const completedPages = pages.filter(p => p.status === 'completed').length
const book = {
path: bookName,
name: bookName,
thumbnail: pages[0]?.thumbnail || null,
totalPages,
completedPages
}
console.log('\n๐ ืืืืืืงื ืืกืคืจ ืฉืืืืืจ:')
console.log(JSON.stringify(book, null, 2))
}
} catch (error) {
console.error('โ ืฉืืืื:', error)
}
}
testAPI()