adb-toolkit/backend_filehttp.go
jegly 26d82c68d5 Add GSI Loader, APK Audit, Firmware, Intent Lab, Screen Mirror, Magisk, and App Lock features; bump to v1.2.0
- New sidebar views: GSI Loader (DSU + permanent fastboot flash), APK Audit,
  Firmware, Intent Lab, Screen Mirror
- New backend modules: backend_gsi.go, backend_apkaudit*.go, backend_firmware.go,
  backend_intent.go, backend_magisk.go, backend_applock.go, backend_scrcpy.go,
  backend_payload.go, backend_privacy.go, backend_overview.go, backend_bootinfo.go,
  backend_flasher.go, backend_transfer.go, backend_filehttp.go
- App Lock / danger-gate infrastructure (DangerGate, LockGate, applock.ts)
- Privileged uninstall via embedded Android helper dex (android-helper/)
- nfpm packaging version bump to 1.2.0
2026-07-06 15:17:59 +10:00

57 lines
1.7 KiB
Go

package main
import (
"net/http"
"os"
"os/exec"
)
// fileHandler serves device/local files to the webview (used by the Files image
// viewer) over the Wails asset server. Streaming raw bytes avoids the size
// limits WebKitGTK imposes on large base64 data: URLs.
//
// Route: /__file?src=device|local&p=<path>
func (a *App) fileHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
p := q.Get("p")
if p == "" {
http.Error(w, "missing path", http.StatusBadRequest)
return
}
w.Header().Set("Cache-Control", "no-store")
if q.Get("src") == "local" {
// ServeFile picks the Content-Type and supports range requests.
http.ServeFile(w, r, p)
return
}
// Device: pull to a temp file via the file-sync protocol, then serve it.
// `adb pull` takes the remote path as a literal argument (no device-shell
// re-parsing), so it handles spaces/parens/etc. — unlike `adb exec-out`,
// which mangles quoted paths. This mirrors the working Pull button.
adbPath, err := a.getBinaryPath("adb")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmp, err := os.CreateTemp("", "atk-view-*")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpPath := tmp.Name()
tmp.Close()
defer os.Remove(tmpPath)
cmd := exec.Command(adbPath, "pull", p, tmpPath)
setCommandSysProcAttr(cmd)
if out, err := cmd.CombinedOutput(); err != nil {
http.Error(w, "failed to read device file: "+string(out), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", mimeForName(p))
http.ServeFile(w, r, tmpPath)
})
}