mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2026-09-27 04:51:45 +00:00
chore: upgrade to typescript 7 with tsconfig strictest
This commit is contained in:
@@ -3,11 +3,12 @@ import { access, constants, writeFile } from 'node:fs/promises'
|
||||
import { basename, resolve } from 'node:path'
|
||||
import { decode } from '@msgpack/msgpack'
|
||||
import pretty from 'pretty-bytes'
|
||||
import { decrypt, deriveKey, setServer, getServer, info, get, decompress } from '@cryptgeon/shared'
|
||||
import { decrypt, deriveKey, setServer, info, get, decompress } from '@cryptgeon/shared'
|
||||
|
||||
export async function download(url: URL, all: boolean, suggestedPassword?: string) {
|
||||
setServer(url.origin)
|
||||
const id = url.pathname.split('/')[2]
|
||||
if (!id) throw new Error('Invalid URL')
|
||||
const meta = await info(id)
|
||||
if (!meta) throw new Error('Note does not exist or is expired')
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { readFile, stat } from 'node:fs/promises'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { basename } from 'node:path'
|
||||
|
||||
import { encode } from '@msgpack/msgpack'
|
||||
import mime from 'mime'
|
||||
import { encrypt, generateKey, deriveKey, randomBytes, setServer, getServer, create, utf8ToBytes, compress } from '@cryptgeon/shared'
|
||||
import { encrypt, generateKey, deriveKey, randomBytes, getServer, create, compress } from '@cryptgeon/shared'
|
||||
|
||||
export type UploadOptions = { views?: number; expiration?: number; password?: string }
|
||||
|
||||
|
||||
+16
-7
@@ -21,7 +21,8 @@ const views = new Option('-v --views <number>', 'Amount of views before getting
|
||||
const minutes = new Option('-m --minutes <number>', 'Minutes before the note expires').argParser(parseNumber)
|
||||
|
||||
// Node 18 guard
|
||||
parseInt(process.version.slice(1).split(',')[0]) < 18 && exit('Node 18 or higher is required')
|
||||
const major = Number(process.version.slice(1).split('.')[0])
|
||||
if (!Number.isFinite(major) || major < 18) exit('Node 18 or higher is required')
|
||||
|
||||
// @ts-ignore
|
||||
const version: string = VERSION
|
||||
@@ -33,10 +34,10 @@ program
|
||||
.description('show information about the server')
|
||||
.addOption(server)
|
||||
.action(async (options) => {
|
||||
setServer(options.server)
|
||||
setServer(options.server!)
|
||||
const response = await status()
|
||||
const formatted = Object.fromEntries(
|
||||
Object.entries({ ...response, max_size: prettyBytes(response.max_size as number) })
|
||||
Object.entries({ ...response, max_size: prettyBytes(response.max_size) })
|
||||
.filter(([key]) => !key.startsWith('theme_'))
|
||||
)
|
||||
console.table(formatted)
|
||||
@@ -51,11 +52,15 @@ send
|
||||
.addOption(minutes)
|
||||
.addOption(password)
|
||||
.action(async (files, options) => {
|
||||
setServer(options.server)
|
||||
setServer(options.server!)
|
||||
await checkConstrains(options)
|
||||
options.password ||= await getStdin()
|
||||
try {
|
||||
const url = await upload(files, { views: options.views, expiration: options.minutes, password: options.password })
|
||||
const url = await upload(files, {
|
||||
...(options.views !== undefined ? { views: options.views } : {}),
|
||||
...(options.minutes !== undefined ? { expiration: options.minutes } : {}),
|
||||
password: options.password,
|
||||
})
|
||||
console.log(`Note created:\n\n${url}`)
|
||||
} catch {
|
||||
exit('Could not create note')
|
||||
@@ -69,11 +74,15 @@ send
|
||||
.addOption(minutes)
|
||||
.addOption(password)
|
||||
.action(async (text, options) => {
|
||||
setServer(options.server)
|
||||
setServer(options.server!)
|
||||
await checkConstrains(options)
|
||||
options.password ||= await getStdin()
|
||||
try {
|
||||
const url = await upload(text, { views: options.views, expiration: options.minutes, password: options.password })
|
||||
const url = await upload(text, {
|
||||
...(options.views !== undefined ? { views: options.views } : {}),
|
||||
...(options.minutes !== undefined ? { expiration: options.minutes } : {}),
|
||||
password: options.password,
|
||||
})
|
||||
console.log(`Note created:\n\n${url}`)
|
||||
} catch {
|
||||
exit('Could not create note')
|
||||
|
||||
@@ -10,8 +10,8 @@ export async function checkConstrains(constrains: { views?: number; minutes?: nu
|
||||
if (!constrains.views && !constrains.minutes) constrains.views = 1
|
||||
|
||||
const response = await status()
|
||||
if (constrains.views && constrains.views > (response.max_views as number))
|
||||
if (constrains.views && constrains.views > response.max_views)
|
||||
exit(`Only a maximum of ${response.max_views} views allowed. ${constrains.views} given.`)
|
||||
if (constrains.minutes && constrains.minutes > (response.max_expiration as number))
|
||||
if (constrains.minutes && constrains.minutes > response.max_expiration)
|
||||
exit(`Only a maximum of ${response.max_expiration} minutes allowed. ${constrains.minutes} given.`)
|
||||
}
|
||||
Reference in New Issue
Block a user