PlainApp
API 參考

訪客 GraphQL

透過分享連結加密存取。

key = Base64UrlDecode(shared_token)分享連結中的 shared_token;c-id = shareId

用戶端
https://<host>:<port>/guest_graphql
伺服器

POST /guest_graphql

c-id: 01a1cd7b-b900-7331-9331-313131313131

HTTP · binary

JSON({ requestId, query, variables })

requestId 為 UUIDv7,內含請求時間;variables、operationName、extensions 可選。

XChaCha20-Poly1305 · 將游標移至欄位或點按
1 / 2

防重放

requestId = UUIDv7()JSON { requestId, query, variables } → authenticated encryption
↓ POST /guest_graphql
驗證並解密shareId → shared_token✕ → 拒絕
↓
檢查 UUIDv7 時間|serverTime − requestId timestamp| ≤ 60 s✕ → 拒絕
↓
執行前記錄 requestIdSQLite: guest + shareId + requestId
✓ ↓執行 GraphQL
✕ ↓拒絕重複的 requestId
函式庫呼叫範例

Desktop 程式碼節錄。共用 graphqlRequestPayload 產生 UUIDv7 requestId,不再傳送獨立 timestamp 或防重放 nonce。

typescript
// plain-desktop/src/lib/api/guest.ts
const payload = graphqlRequestPayload(query, variables)
const requestBody = chachaEncrypt(key, payload, httpRequestAad('/guest_graphql'))
const response = await httpRequest(url, {
  method: 'POST', headers: { 'c-id': shareId }, body: requestBody
})
if (!response.ok) throw new Error(String(response.status))
const bytes = new Uint8Array(await response.arrayBuffer())
const result = JSON.parse(decryptGraphqlResponse(key, requestBody, bytes))
// Feature error codes are carried in extensions.code; message is diagnostic text.
if (result.errors?.length) throw GqlError.fromGraphql(result.errors[0])

HTTP 403:分享失效或遠端存取關閉。401:解密失敗。400:請求格式錯誤、過期或重複。

型別定義

graphql
scalar Instant

scalar Long

type Query {
	sharedInfo(relativePath: String, password: String): SharedInfo!
}

type SharedFile {
	name: String!
	relativePath: String!
	isDir: Boolean!
	size: Long!
	mimeType: String!
	hasThumb: Boolean!
	createdAt: Instant
	updatedAt: Instant!
}

type SharedInfo {
	name: String!
	readOnly: Boolean!
	requiresPassword: Boolean!
	expiresAt: Instant
	urlToken: String!
	entries: [SharedFile!]!
}

"""
Directs the executor to include this field or fragment only when the `if` argument is true.
"""
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
"""
Directs the executor to skip this field or fragment when the `if` argument is true.
"""
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
schema {
	query: Query
}