cdrop — 跨 OS 剪贴板与文件传输服务
Commilitia Drop:自托管的跨设备剪贴板同步与点对点文件传输。 - 后端 Go(chi / SQLite WAL / SSE Hub / WebRTC signaling + 状态机 / Relay ring buffer),编译进单个 distroless 镜像(前端 go:embed)。 - 前端 React + TanStack Router + Zustand,自实现 SSE + WebRTC P2P,NAT 受阻时回退服务端中继;聚珍(Juzhen)CJK 综合排版。 - 桌面端 Wails v2(macOS / Windows),瘦客户端复用 web。 - 鉴权 OIDC PKCE(自建 Casdoor 等),refresh_token 信封加密存系统密钥库;iOS Shortcut 用 HS256 scoped token。 架构文档与变更记录见 docs 分支(PROJECT_BRIEF / FRONTEND_DESIGN / CHANGELOG)。 本次为公开发布初始提交:完整开发历史(含部署细节)留存于私有归档,公开仓库自此干净起步。
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: clipboard.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const clearExpiredClipboards = `-- name: ClearExpiredClipboards :execrows
|
||||
UPDATE clipboard_state
|
||||
SET content =
|
||||
`
|
||||
|
||||
// 清除 updated_at 早于 cutoff 的剪贴板内容(content / source_device 置空),
|
||||
// 由 sweeper 周期调用实现短 TTL;保留行本身、仅抹掉内容。
|
||||
func (q *Queries) ClearExpiredClipboards(ctx context.Context, updatedAt int64) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, clearExpiredClipboards, updatedAt)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const getClipboard = `-- name: GetClipboard :one
|
||||
SELECT user_id, content_type, content, source_device, updated_at, version, origin_ts
|
||||
FROM clipboard_state
|
||||
WHERE user_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetClipboard(ctx context.Context, userID string) (ClipboardState, error) {
|
||||
row := q.db.QueryRowContext(ctx, getClipboard, userID)
|
||||
var i ClipboardState
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.ContentType,
|
||||
&i.Content,
|
||||
&i.SourceDevice,
|
||||
&i.UpdatedAt,
|
||||
&i.Version,
|
||||
&i.OriginTs,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const upsertClipboard = `-- name: UpsertClipboard :one
|
||||
INSERT INTO clipboard_state (user_id, content_type, content, source_device, updated_at, version, origin_ts)
|
||||
VALUES (?, ?, ?, ?, ?, 1, ?)
|
||||
ON CONFLICT (user_id) DO UPDATE SET
|
||||
content_type = excluded.content_type,
|
||||
content = excluded.content,
|
||||
source_device = excluded.source_device,
|
||||
updated_at = excluded.updated_at,
|
||||
version = clipboard_state.version + 1,
|
||||
origin_ts = excluded.origin_ts
|
||||
WHERE excluded.origin_ts > clipboard_state.origin_ts
|
||||
RETURNING version
|
||||
`
|
||||
|
||||
type UpsertClipboardParams struct {
|
||||
UserID string `json:"user_id"`
|
||||
ContentType string `json:"content_type"`
|
||||
Content *string `json:"content"`
|
||||
SourceDevice *string `json:"source_device"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
OriginTs int64 `json:"origin_ts"`
|
||||
}
|
||||
|
||||
// New rows start version 1; conflicts bump version by 1 (per-user monotonic).
|
||||
// LWW: the DO UPDATE only runs when the new origin_ts is strictly greater than
|
||||
// the stored one, so a delayed / out-of-order older copy changes nothing and
|
||||
// RETURNING yields no row (the service reads sql.ErrNoRows as "stale, rejected").
|
||||
func (q *Queries) UpsertClipboard(ctx context.Context, arg UpsertClipboardParams) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, upsertClipboard,
|
||||
arg.UserID,
|
||||
arg.ContentType,
|
||||
arg.Content,
|
||||
arg.SourceDevice,
|
||||
arg.UpdatedAt,
|
||||
arg.OriginTs,
|
||||
)
|
||||
var version int64
|
||||
err := row.Scan(&version)
|
||||
return version, err
|
||||
}
|
||||
Reference in New Issue
Block a user