feat(drone-dock): 实现局域网扫码直传交付
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import Foundation
|
||||
|
||||
/// 随 App 分发的局域网接收页;纯 HTML/CSS,不请求远程资源,也不在浏览器内缓存整段视频。
|
||||
enum DroneDockNearbyTransferPage {
|
||||
/// 生成单个视频的下载页,仅接受当前局域网会话格式的相对下载路径。
|
||||
static func html(video: DroneDockDeliveryVideo, downloadPath: String) -> String {
|
||||
let fileName = escape(video.fileName)
|
||||
let size = escape(ByteCountFormatter.string(fromByteCount: Int64(max(0, video.fileSize)), countStyle: .file))
|
||||
let isValidPath = downloadPath.range(of: #"\A/s/[0-9a-f]{64}/video\z"#, options: .regularExpression) != nil
|
||||
let download: String
|
||||
if isValidPath {
|
||||
download = """
|
||||
<a class="download" href="\(escape(downloadPath))" download aria-label="下载视频">下载视频 <span aria-hidden="true">↓</span></a>
|
||||
<p class="download-note">点击后,请在浏览器下载列表查看进度。</p>
|
||||
"""
|
||||
} else {
|
||||
download = """
|
||||
<p class="unavailable" role="status">下载链接不可用,请让商家重新生成二维码。</p>
|
||||
"""
|
||||
}
|
||||
return """
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<meta name="referrer" content="no-referrer">
|
||||
<meta name="color-scheme" content="light">
|
||||
<title>面对面闪传 · 随心瞰</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; color: #162b24; background: #f4f7f5; font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
|
||||
main { width: 100%; max-width: 500px; margin: 0 auto; padding: 30px 20px calc(28px + env(safe-area-inset-bottom)); }
|
||||
.brand { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 650; color: #53675d; }
|
||||
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; background: #16845c; color: white; border-radius: 8px; font-size: 15px; }
|
||||
.intro { margin: 32px 0 24px; }
|
||||
.badge { display: inline-flex; align-items: center; gap: 6px; color: #167b55; background: #e5f3eb; border-radius: 20px; padding: 4px 10px; font-size: 12px; font-weight: 600; }
|
||||
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #16845c; }
|
||||
h1 { font-size: 28px; line-height: 1.3; letter-spacing: -.6px; margin: 15px 0 9px; }
|
||||
.subtitle { margin: 0; color: #68796f; font-size: 14px; }
|
||||
.file-card { background: #fff; border: 1px solid #e3ebe6; border-radius: 22px; padding: 24px 20px 20px; box-shadow: 0 8px 28px #16382906; }
|
||||
.file-row { display: flex; align-items: center; gap: 13px; margin-bottom: 24px; }
|
||||
.file-icon { display: grid; place-items: center; flex: 0 0 50px; height: 58px; border-radius: 13px; background: #edf6f0; color: #16845c; font-size: 22px; }
|
||||
.file-info { min-width: 0; }
|
||||
.file-name { margin: 0; font-size: 16px; font-weight: 650; line-height: 1.5; overflow-wrap: anywhere; }
|
||||
.file-size { margin: 5px 0 0; color: #7b8981; font-size: 13px; }
|
||||
.download { display: flex; min-height: 52px; align-items: center; justify-content: center; gap: 12px; border-radius: 14px; background: #16845c; color: #fff; text-decoration: none; font-weight: 650; -webkit-tap-highlight-color: transparent; }
|
||||
.download:active { background: #106846; }
|
||||
.download:focus-visible, summary:focus-visible { outline: 3px solid #78bda0; outline-offset: 4px; }
|
||||
.download span { font-size: 22px; line-height: 1; }
|
||||
.download-note { margin: 12px 0 0; text-align: center; font-size: 12px; color: #7b8981; }
|
||||
.unavailable { background: #fff4e6; color: #8b591a; padding: 14px; border-radius: 12px; font-size: 14px; }
|
||||
.connection { display: flex; align-items: flex-start; gap: 10px; margin: 18px 2px 25px; color: #64766b; font-size: 13px; }
|
||||
.connection-mark { color: #16845c; font-size: 16px; line-height: 1.5; }
|
||||
.connection p { margin: 0; }
|
||||
.help { border-top: 1px solid #dfe8e2; }
|
||||
details { border-bottom: 1px solid #dfe8e2; padding: 15px 0; }
|
||||
summary { cursor: pointer; font-size: 14px; font-weight: 600; }
|
||||
details p { margin: 10px 0 0; padding-left: 15px; color: #68796f; font-size: 13px; }
|
||||
.footer { margin-top: 26px; color: #91a096; text-align: center; font-size: 12px; }
|
||||
@media (min-width: 600px) { main { padding-top: 48px; } }
|
||||
@media (prefers-reduced-motion: no-preference) { .download { transition: background .15s; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="brand"><span class="brand-mark" aria-hidden="true">瞰</span>随心瞰 · 面对面闪传</div>
|
||||
<header class="intro">
|
||||
<span class="badge">本地直传</span>
|
||||
<h1>你的航拍作品<br>就在这里</h1>
|
||||
<p class="subtitle">视频由附近的商家手机直接提供。</p>
|
||||
</header>
|
||||
<section class="file-card" aria-label="待接收视频">
|
||||
<div class="file-row">
|
||||
<div class="file-icon" aria-hidden="true">▶</div>
|
||||
<div class="file-info">
|
||||
<p class="file-name">\(fileName)</p>
|
||||
<p class="file-size">视频文件 · \(size)</p>
|
||||
</div>
|
||||
</div>
|
||||
\(download)
|
||||
</section>
|
||||
<div class="connection">
|
||||
<span class="connection-mark" aria-hidden="true">◎</span>
|
||||
<p>双方请保持连接同一个 Wi-Fi。<br>传输期间,请让商家保持闪传页面亮屏。</p>
|
||||
</div>
|
||||
<section class="help" aria-label="接收帮助">
|
||||
<details>
|
||||
<summary>iPhone 下载后在哪里查看?</summary>
|
||||
<p>建议使用 Safari 打开。下载前,可在系统设置中的 Safari 下载设置里选择“我的 iPhone”,避免保存到 iCloud Drive。</p>
|
||||
<p>下载完成后,在“文件”App 的“下载”文件夹打开视频。格式受支持时,可通过分享菜单选择“存储视频”保存到相册。</p>
|
||||
</details>
|
||||
<details>
|
||||
<summary>安卓下载后在哪里查看?</summary>
|
||||
<p>请在浏览器的“下载内容”或手机文件管理的“下载”文件夹中查看。是否显示在相册中取决于手机和视频格式。</p>
|
||||
</details>
|
||||
<details>
|
||||
<summary>无法下载或传输中断怎么办?</summary>
|
||||
<p>请先确认双方仍连接同一个 Wi-Fi,商家没有关闭闪传页面,再点击下载重试。部分公共 Wi-Fi 会限制手机之间连接,可以更换网络后重新扫码。</p>
|
||||
<p>本次链接短时有效。商家结束闪传后链接会失效,需要重新生成二维码。</p>
|
||||
</details>
|
||||
</section>
|
||||
<p class="footer">无需安装 App · 接收后请核对视频是否完整</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
}
|
||||
|
||||
private static func escape(_ value: String) -> String {
|
||||
value.replacingOccurrences(of: "&", with: "&")
|
||||
.replacingOccurrences(of: "<", with: "<")
|
||||
.replacingOccurrences(of: ">", with: ">")
|
||||
.replacingOccurrences(of: "\"", with: """)
|
||||
.replacingOccurrences(of: "'", with: "'")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user