This commit is contained in:
2023-04-27 19:01:32 +02:00
parent 55b6e9ea51
commit 86cdb6d5da
7 changed files with 25 additions and 120 deletions

View File

@@ -24,7 +24,6 @@ export async function download(url: URL) {
exit('No files found in note')
return
}
console.log(files)
const { names } = await inquirer.prompt([
{
type: 'checkbox',
@@ -50,7 +49,7 @@ export async function download(url: URL) {
await access(filename, constants.R_OK)
filename = resolve(`${Date.now()}-${file.name}`)
} catch {}
await writeFile(filename, new Uint8Array(await file.contents.arrayBuffer()))
await writeFile(filename, file.contents)
console.log(`Saved: ${basename(filename)}`)
})
)

View File

@@ -2,6 +2,7 @@
import { Argument, Option, program } from '@commander-js/extra-typings'
import { setBase, status } from '@cryptgeon/shared'
import prettyBytes from 'pretty-bytes'
import { download } from './download.js'
import { parseFile, parseNumber } from './parsers.js'
@@ -37,10 +38,14 @@ program
.action(async (options) => {
setBase(options.server)
const response = await status()
for (const key of Object.keys(response)) {
if (key.startsWith('theme_')) delete response[key as keyof typeof response]
const formatted = {
...response,
max_size: prettyBytes(response.max_size),
}
console.table(response)
for (const key of Object.keys(formatted)) {
if (key.startsWith('theme_')) delete formatted[key as keyof typeof formatted]
}
console.table(formatted)
})
const send = program.command('send')

View File

@@ -1,10 +1,10 @@
import { InvalidArgumentError, InvalidOptionArgumentError } from '@commander-js/extra-typings'
import { accessSync, constants } from 'node:fs'
import path from 'node:path'
import { resolve } from 'node:path'
export function parseFile(value: string, before: string[] = []) {
try {
const file = path.resolve(value)
const file = resolve(value)
accessSync(file, constants.R_OK)
return [...before, file]
} catch {

View File

@@ -3,7 +3,7 @@ import { readFile, stat } from 'node:fs/promises'
import { basename } from 'node:path'
import { Adapters, BASE, create, FileDTO, Note } from '@cryptgeon/shared'
import mime from 'mime'
import * as mime from 'mime'
import { AES, Hex, TypedArray } from 'occulto'
import { exit } from './utils.js'
@@ -32,9 +32,9 @@ export async function uploadFiles(paths: string[], options: UploadOptions) {
return {
name: basename(path),
size: stats.size,
contents: new Blob([data]) as FileDTO['contents'],
contents: data,
type,
}
} satisfies FileDTO
})
)

View File

@@ -1,6 +1,6 @@
import process from 'node:process'
import { exit as exitNode } from 'node:process'
export function exit(message: string) {
console.error(message)
process.exit(1)
exitNode(1)
}