Tham chiếu API

GraphQL cho khách

Truy cập mã hóa qua liên kết chia sẻ.

key = Base64UrlDecode(shared_token)shared_token từ liên kết chia sẻ; c-id = shareId

Máy khách
https://<host>:<port>/guest_graphql
Máy chủ

POST /guest_graphql

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

HTTP · binary

JSON({ requestId, query, variables })

requestId là UUIDv7 và chứa thời gian yêu cầu. variables, operationName và extensions là tùy chọn.

XChaCha20-Poly1305 · Di chuột hoặc chạm một trường
1 / 2

Chống phát lại

requestId = UUIDv7()JSON { requestId, query, variables } → authenticated encryption
↓ POST /guest_graphql
Xác thực và giải mãshareId → shared_token✕ → Từ chối
↓
Kiểm tra thời gian UUIDv7|serverTime − requestId timestamp| ≤ 60 s✕ → Từ chối
↓
Lưu requestId trước khi thực thiSQLite: guest + shareId + requestId
✓ ↓Thực thi GraphQL
✕ ↓Từ chối requestId đã dùng
Lệnh gọi thư viện

Trích đoạn Desktop. Cùng hàm trợ giúp graphqlRequestPayload tạo requestId UUIDv7; không gửi dấu thời gian hoặc nonce chống phát lại riêng.

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: chia sẻ không hoạt động hoặc truy cập từ xa bị tắt. 401: giải mã thất bại. 400: yêu cầu sai định dạng, hết hạn hoặc lặp lại.

Định nghĩa kiểu

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
}