Piik now has one public presentation and a coordinated App/Server release path. This phase unifies the room UI, rewrites the bilingual README and guides, adds a static website with an inline product film, and prepares matching GitHub/Gitee packages and update links. The film uses the current homepage and shared product controls on one seekable timeline. Runtime fixes preserve presentation when the App opens a room, normalize Site origins, and keep capture and media-recovery status in the television indicator. New visits use Chinese for a Chinese system language and English otherwise; explicit language and visual-mode choices remain available. An optional site passphrase controls site entry, while room authorization remains enforced. GitHub is the release authority. Gitee mirrors verified packages and provides update metadata when GitHub is unavailable. Reviewed PR release notes become the GitHub Release description. The separate public demo uses P2P only, with HTTPS and STUN verified. Validation: 756 Web tests, TypeScript and production build; Go core tests, formatting, vet and available target builds; bounded Windows capture and App/Site interoperability; browser film checks, audible playback and narrow layouts; anonymous Gitee Windows-package download, checksum and launcher/update-link checks. Public demo acceptance covers authenticated WebSocket signaling, synthetic P2P video and room cleanup on one network. macOS/Linux physical capture and the wider device/network/endurance matrix remain explicitly deferred. Publication builds every package from the merged source SHA. The repository is public, main protection is active, and Pages is configured for piik.tv. CI/publisher and Pages deployment records own publication results. ## Release notes ### 中文 Piik 是免费开源的屏幕共享工具。开个房间,发出邀请,最多 20 位朋友就能用浏览器加入观看。 - 使用浏览器或 Piik App 分享游戏、窗口和整个屏幕。 - 优先建立直连;自托管站点可开启媒体转发作为备用线路。 - Piik App 支持本地房间、临时公网邀请和已有站点。 - Piik Server 内置网页界面、房间管理和连接服务,方便自行部署。 - 提供中英文界面与使用指南,以及 GitHub、Gitee 两条下载线路。 [官网](https://piik.tv) · [在线体验](https://demo.piik.tv) · [使用指南](https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/getting-started.zh-CN.md) · [自行部署](https://github.com/TNTcraftHIM/Piik/blob/main/docs/operations/self-hosting.zh-CN.md) · [Gitee 下载](https://gitee.com/TNTcraftHIM/Piik/releases) Windows App 和桌面浏览器是本次主要验证的平台。macOS 和 Linux 尚未经过实机测试,欢迎有设备的朋友测试并反馈。演示站和 App 公网邀请使用 P2P,受限网络下可能无法连接;自托管站点可开启媒体转发。 ### English Piik is free, open-source screen sharing for you and up to 20 viewers. Start a room, send an invitation, and your friends can join in a browser. - Share games, windows or a whole screen from your browser or Piik App. - Direct connections come first, with optional media forwarding on self-hosted sites. - Piik App supports local rooms, temporary public invitations and existing sites. - Piik Server includes the web interface, rooms and connection services for self-hosting. - English and Chinese interfaces and guides are available, with GitHub and Gitee downloads. [Website](https://piik.tv) · [Online demo](https://demo.piik.tv) · [User guide](https://github.com/TNTcraftHIM/Piik/blob/main/docs/guide/getting-started.md) · [Self-hosting](https://github.com/TNTcraftHIM/Piik/blob/main/docs/operations/self-hosting.md) · [Gitee downloads](https://gitee.com/TNTcraftHIM/Piik/releases) Windows App and desktop browsers are the primary validated paths. macOS and Linux have not yet been tested on physical devices; testing and feedback are welcome. The demo and App public invitations rely on P2P and may not connect on restrictive networks. Self-hosted sites can enable media forwarding.
156 lines
5.2 KiB
Go
156 lines
5.2 KiB
Go
package app
|
|
|
|
import (
|
|
"io"
|
|
"io/fs"
|
|
"net/http"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/TNTcraftHIM/Piik/internal/server/protocol"
|
|
)
|
|
|
|
// staticContentTypes fixes the MIME types for this repository's Web assets.
|
|
// Go's mime.TypeByExtension overlays the Windows
|
|
// registry or /etc/mime.types, so the served Content-Type would otherwise
|
|
// depend on the machine; with X-Content-Type-Options: nosniff a wrong type on a
|
|
// font or a webmanifest is user visible.
|
|
var staticContentTypes = map[string]string{
|
|
".html": "text/html;charset=utf-8", // sirv appends ";charset=utf-8" with no space
|
|
".htm": "text/html;charset=utf-8",
|
|
".js": "text/javascript",
|
|
".mjs": "text/javascript",
|
|
".css": "text/css",
|
|
".json": "application/json",
|
|
".map": "application/json",
|
|
".txt": "text/plain",
|
|
".svg": "image/svg+xml",
|
|
".png": "image/png",
|
|
".jpg": "image/jpeg",
|
|
".jpeg": "image/jpeg",
|
|
".webp": "image/webp",
|
|
".gif": "image/gif",
|
|
".avif": "image/avif",
|
|
".woff": "font/woff",
|
|
".woff2": "font/woff2",
|
|
".ttf": "font/ttf",
|
|
".otf": "font/otf",
|
|
".wasm": "application/wasm",
|
|
".webmanifest": "application/manifest+json",
|
|
".bin": "application/octet-stream",
|
|
".xml": "text/xml",
|
|
".ico": "", // mrmime has no .ico, so sirv sends an EMPTY Content-Type
|
|
}
|
|
|
|
// staticHandler serves embedded assets and falls back to index.html for SPA
|
|
// routes. Missing files use the application's JSON 404 handler.
|
|
func staticHandler(assets fs.FS, notFound http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
|
// API and health routes have already been handled by ServeHTTP.
|
|
cleaned := path.Clean("/" + request.URL.Path)
|
|
name := strings.TrimPrefix(cleaned, "/")
|
|
|
|
serve := func(candidate string) bool {
|
|
// Clean traversal segments and exclude hidden assets before opening.
|
|
if candidate == "" || hasDotSegment(candidate) {
|
|
return false
|
|
}
|
|
file, err := assets.Open(candidate)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
defer file.Close()
|
|
info, err := file.Stat()
|
|
if err != nil || info.IsDir() {
|
|
return false
|
|
}
|
|
seeker, ok := file.(io.ReadSeeker)
|
|
if !ok {
|
|
return false
|
|
}
|
|
writer.Header().Set("X-Content-Type-Options", "nosniff")
|
|
writer.Header().Set("Referrer-Policy", "no-referrer")
|
|
// Set Content-Type explicitly, possibly to "", so ServeContent
|
|
// never sniffs; the empty name keeps it from guessing either.
|
|
writer.Header()["Content-Type"] = []string{staticContentTypes[strings.ToLower(path.Ext(candidate))]}
|
|
// embed.FS reports a zero ModTime; do not fabricate Last-Modified.
|
|
http.ServeContent(writer, request, "", info.ModTime(), seeker)
|
|
return true
|
|
}
|
|
|
|
// sirv strips a trailing "/" before the lookup, and its FILES map holds
|
|
// files only, so "/assets/" can never hit a file.
|
|
if !strings.HasSuffix(request.URL.Path, "/") && serve(name) {
|
|
return
|
|
}
|
|
// opts.single: fall back to index.html unless the request matches one
|
|
// of sirv's two default ignores.
|
|
if !looksLikeFile(cleaned) && !strings.Contains(cleaned, "/.well-known") {
|
|
if serve("index.html") {
|
|
return
|
|
}
|
|
}
|
|
notFound.ServeHTTP(writer, request)
|
|
})
|
|
}
|
|
|
|
// hasDotSegment reports whether any path segment starts with '.', reproducing
|
|
// totalist's filter `!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)` together
|
|
// with the `/\.well-known[\\+\/]/` exemption that runs before it.
|
|
func hasDotSegment(name string) bool {
|
|
if strings.Contains(name, ".well-known/") {
|
|
return false
|
|
}
|
|
for _, segment := range strings.Split(name, "/") {
|
|
if strings.HasPrefix(segment, ".") {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// looksLikeFile ports sirv's default "any extn" ignore,
|
|
// /[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/. Because the character class excludes
|
|
// "/" and the match is anchored at the end, only the last path segment can
|
|
// match: it must contain a dot with a non-empty [A-Za-z0-9_] extension after
|
|
// it, and everything before that dot must be in the class. The class is
|
|
// ASCII-only, so "/文件.js" and "/café.css" are NOT ignored and do get the
|
|
// index.html fallback.
|
|
func looksLikeFile(pathname string) bool {
|
|
slash := strings.LastIndexByte(pathname, '/')
|
|
if slash < 0 {
|
|
return false
|
|
}
|
|
segment := pathname[slash+1:]
|
|
dot := strings.LastIndexByte(segment, '.')
|
|
if dot <= 0 || dot == len(segment)-1 {
|
|
return false
|
|
}
|
|
for _, character := range segment[:dot] { // [A-Za-z\s\d~$._-]
|
|
switch {
|
|
case character >= 'A' && character <= 'Z',
|
|
character >= 'a' && character <= 'z',
|
|
character >= '0' && character <= '9',
|
|
character == '~', character == '$', character == '.',
|
|
character == '_', character == '-',
|
|
// URL paths are percent-decoded before this test, so a non-ASCII
|
|
// space can genuinely reach it; protocol owns the JavaScript
|
|
// whitespace class.
|
|
protocol.IsJSWhitespace(character):
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
for _, character := range segment[dot+1:] { // \w+
|
|
switch {
|
|
case character >= 'A' && character <= 'Z',
|
|
character >= 'a' && character <= 'z',
|
|
character >= '0' && character <= '9',
|
|
character == '_':
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|