初始提交: ScriptForge 脚本快速转运行链接服务
Some checks failed
Release / build-and-release (push) Failing after 1m31s
Some checks failed
Release / build-and-release (push) Failing after 1m31s
- Go 后端 (Gin + GORM + SQLite) 提供 API 和纯文本脚本服务 - Vite + React + TypeScript + Tailwind 前端 - 单二进制部署 (Go embed 前端静态文件) - Gitea Actions CI/CD: 打标签自动构建多平台 Release - 支持 bash/zsh/sh/fish/python3/node/ruby/php 8种运行环境 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
44
frontend/src/lib/api.ts
Normal file
44
frontend/src/lib/api.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { CreateScriptResponse, ScriptDetail, RuntimeOption, ExpiresIn } from '../types'
|
||||
|
||||
const BASE = ''
|
||||
|
||||
async function request<T>(url: string, options?: RequestInit): Promise<T> {
|
||||
const res = await fetch(BASE + url, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
...options,
|
||||
})
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({ error: res.statusText }))
|
||||
throw new Error(body.error || `HTTP ${res.status}`)
|
||||
}
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export async function createScript(params: {
|
||||
content: string
|
||||
runtime: RuntimeOption
|
||||
expires_in: ExpiresIn
|
||||
}): Promise<CreateScriptResponse> {
|
||||
return request('/api/scripts', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(params),
|
||||
})
|
||||
}
|
||||
|
||||
export async function getScript(id: string): Promise<ScriptDetail> {
|
||||
return request(`/api/scripts/${id}`)
|
||||
}
|
||||
|
||||
export async function deleteScript(id: string, token: string): Promise<void> {
|
||||
await fetch(`${BASE}/api/scripts/${id}?token=${encodeURIComponent(token)}`, {
|
||||
method: 'DELETE',
|
||||
}).then((res) => {
|
||||
if (!res.ok && res.status !== 204) {
|
||||
throw new Error('delete failed')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function getCommandUrl(id: string): string {
|
||||
return `${window.location.origin}/raw/${id}`
|
||||
}
|
||||
Reference in New Issue
Block a user