Documentation
¶
Overview ¶
Package impl providers the main implementation of sync server APIs.
Index ¶
- Constants
- Variables
- func BuildAudioThumbnail(userName string, deviceId string, file string) (string, error)
- func BuildImageThumbnail(userName string, deviceId string, file string) (string, error)
- func BuildVideoThumbnail(userName string, deviceId string, file string) (string, error)
- func CleanOrphanThumbnailsHandler(w http.ResponseWriter, r *http.Request)
- func ExtractMetadata(userName string, deviceId string, file string) (string, error)
- func GetFilesHandler(w http.ResponseWriter, r *http.Request)
- func GetFoldersHandler(w http.ResponseWriter, r *http.Request)
- func GetFrameFromVideo(inFileName string, frameNum int) io.Reader
- func GetImageHandler(w http.ResponseWriter, r *http.Request)
- func GetOrientationFromMetadata(metadataPath string) int
- func GetStreamHandler(w http.ResponseWriter, r *http.Request)
- func InvalidFileTypeUploaded(fileType string) error
- func IsImagePath(path string) bool
- func ListAllRelativeFiles(userDir string) ([]string, error)
- func ListTrashFiles(userDir string) ([]string, error)
- func LoginHandler(w http.ResponseWriter, r *http.Request)
- func LooksLikeDocument(fullPath string) bool
- func MetadataPath(userDir, file string) string
- func MoveRelativePathToTrash(userDir, relPath string)
- func MoveToTrashHandler(w http.ResponseWriter, r *http.Request)
- func RegenerateThumbnailsHandler(w http.ResponseWriter, r *http.Request)
- func RegisterHandler(w http.ResponseWriter, r *http.Request)
- func ResolveToUserId(user string) string
- func RestoreHandler(w http.ResponseWriter, r *http.Request)
- func RunDocumentClassifierAsync(fullPath, userDir, relPath string)
- func RunDocumentClassifierSync(fullPath, userDir, relPath string)
- func RunDocumentClassifierSyncReturnsMoved(fullPath, userDir, relPath string) bool
- func RunDocumentDetectionHandler(w http.ResponseWriter, r *http.Request)
- func SetupInfoHandler(w http.ResponseWriter, r *http.Request)
- func ThumbnailBasePath(userDir, file string) string
- func UploadHandler(w http.ResponseWriter, r *http.Request)
- type RequestError
Constants ¶
const TrashFolder = "Trash"
Variables ¶
var BuildThumbnailFailed = errors.Errorf("Creating thumbnail failed.").Err
An error for empty storage path.
var FileSizeExceeded = errors.Errorf("Maximum file size for uploaded files exceeded.").Err
An error for empty storage path.
var MissingDateClassifier = errors.Errorf("Missing date classifier.").Err
An error for missing date classifier.
var MissingUser = errors.Errorf("The user is not authorized.").Err
An error for missing authorized user.
var WrongDateClassifier = errors.Errorf("Wrong date classifier.").Err
An error for wrong date classifier.
Functions ¶
func BuildAudioThumbnail ¶ added in v1.0.5
func BuildImageThumbnail ¶ added in v1.0.5
func BuildVideoThumbnail ¶ added in v1.0.5
func CleanOrphanThumbnailsHandler ¶ added in v1.0.7
func CleanOrphanThumbnailsHandler(w http.ResponseWriter, r *http.Request)
CleanOrphanThumbnailsHandler deletes thumbnail and metadata files that have no corresponding source file. POST body: { "UserData": { "User": "", "DeviceId": "" } }
func ExtractMetadata ¶ added in v1.0.5
func GetFilesHandler ¶ added in v1.0.2
func GetFilesHandler(w http.ResponseWriter, r *http.Request)
func GetFoldersHandler ¶ added in v1.0.2
func GetFoldersHandler(w http.ResponseWriter, r *http.Request)
func GetFrameFromVideo ¶ added in v1.0.5
func GetImageHandler ¶ added in v1.0.3
func GetImageHandler(w http.ResponseWriter, r *http.Request)
func GetOrientationFromMetadata ¶ added in v1.0.7
GetOrientationFromMetadata reads the EXIF Orientation (1-8) from a metadata JSON file. Returns 1 (normal) if the file is missing, invalid, or Orientation is absent.
func GetStreamHandler ¶ added in v1.0.7
func GetStreamHandler(w http.ResponseWriter, r *http.Request)
GetStreamHandler serves raw media files (video/audio) with HTTP Range support for streaming and seeking without full download. GET /stream?User=...&DeviceId=...&File=... (File is URL-encoded path, e.g. 2024/01/video.mp4)
func InvalidFileTypeUploaded ¶
An error for invalid file type, which is not allowed to be uploaded.
func IsImagePath ¶ added in v1.0.7
IsImagePath returns true if the file extension is a common image type (case-insensitive).
func ListAllRelativeFiles ¶ added in v1.0.7
ListAllRelativeFiles returns relative paths (forward slashes) of all files under userDir, excluding Trash, Thumbnails, and Metadata directories.
func ListTrashFiles ¶ added in v1.0.7
ListTrashFiles returns relative paths of main files under userDir/Trash (e.g. "Trash/2024/01/photo.jpg"). Skips Trash/Thumbnails and Trash/Metadata so only media files are listed.
func LoginHandler ¶ added in v1.0.7
func LoginHandler(w http.ResponseWriter, r *http.Request)
LoginHandler validates user/password and returns a session token. POST body: { "User": "", "Password": "" } -> { "Token": "" } or 401.
func LooksLikeDocument ¶ added in v1.0.7
LooksLikeDocument returns true if the image appears to be a document, whiteboard, notebook, textbook or book page (flat, text-heavy). Uses a simple heuristic: high mean brightness and bimodal brightness (lots of light + dark pixels). May have false positives (e.g. white wall, bright sky) and false negatives (dark pages, low contrast). Only call for image files.
func MetadataPath ¶ added in v1.0.7
MetadataPath returns the full path to the metadata JSON file. For files in Trash, metadata lives under Trash/Metadata/; otherwise under Metadata/.
func MoveRelativePathToTrash ¶ added in v1.0.7
func MoveRelativePathToTrash(userDir, relPath string)
MoveRelativePathToTrash moves one file (and its thumbnail and metadata) from the normal folder to Trash. relPath is e.g. "2024/01/photo.jpg". No-op if relPath is already under Trash. Used by upload when document detection is enabled.
func MoveToTrashHandler ¶ added in v1.0.7
func MoveToTrashHandler(w http.ResponseWriter, r *http.Request)
MoveToTrashHandler moves files (and their thumbnails and metadata) to Trash. POST body: { "UserData": { "User": "", "DeviceId": "" }, "Files": ["2024/01/photo.jpg", ...] }
func RegenerateThumbnailsHandler ¶ added in v1.0.7
func RegenerateThumbnailsHandler(w http.ResponseWriter, r *http.Request)
RegenerateThumbnailsHandler regenerates thumbnails for all media files (excluding Trash). POST body: { "UserData": { "User": "", "DeviceId": "" } }
func RegisterHandler ¶ added in v1.0.7
func RegisterHandler(w http.ResponseWriter, r *http.Request)
RegisterHandler creates a user. POST body: { "User": "", "Password": "" }.
func ResolveToUserId ¶ added in v1.0.7
ResolveToUserId returns the folder name used for storage path (UploadDirectory/<this>/deviceId). Always returns normalized (lowercase) email so the main folder is the user's email. When auth DB is set: User in requests can be username (email) or userId; we resolve to email for path. When auth DB is not set: returns lowercase user as-is.
func RestoreHandler ¶ added in v1.0.7
func RestoreHandler(w http.ResponseWriter, r *http.Request)
RestoreHandler moves files from Trash back to their original folder (by path). POST body: { "UserData": { "User": "", "DeviceId": "" }, "Files": ["Trash/2024/01/photo.jpg", ...] }
func RunDocumentClassifierAsync ¶ added in v1.0.7
func RunDocumentClassifierAsync(fullPath, userDir, relPath string)
RunDocumentClassifierAsync runs the configured Python/exe classifier in a new goroutine. After sync, if stdout contains "document", the file is moved to Trash. fullPath is the absolute path to the image; userDir and relPath are for MoveRelativePathToTrash.
func RunDocumentClassifierSync ¶ added in v1.0.7
func RunDocumentClassifierSync(fullPath, userDir, relPath string)
RunDocumentClassifierSync runs the classifier and, if stdout contains "document", moves the file to Trash. Call this after thumbnail creation so the thumbnail is moved to Trash/Thumbnails together with the file.
func RunDocumentClassifierSyncReturnsMoved ¶ added in v1.0.7
RunDocumentClassifierSyncReturnsMoved runs the classifier and, if stdout contains "document", moves the file to Trash. Returns true if the file was moved to Trash.
func RunDocumentDetectionHandler ¶ added in v1.0.7
func RunDocumentDetectionHandler(w http.ResponseWriter, r *http.Request)
RunDocumentDetectionHandler runs document detection (Python classifier or built-in heuristic) on existing image files, moves detected documents to Trash (with thumbnails and metadata). Returns { "Moved": N }. POST body: { "UserData": { "User": "", "DeviceId": "" } }
func SetupInfoHandler ¶
func SetupInfoHandler(w http.ResponseWriter, r *http.Request)
func ThumbnailBasePath ¶ added in v1.0.7
ThumbnailBasePath returns the full path to the thumbnail file (without .jpeg extension for videos). For files in Trash, thumbnails live under Trash/Thumbnails/ (not Thumbnails/Trash/); otherwise under Thumbnails/.
func UploadHandler ¶
func UploadHandler(w http.ResponseWriter, r *http.Request)
Upload file handler for uploading large streamed files. A new file is saved under a directory named like the client device. An error will be rendered in the response if: - the file already exists; - the maximum allowed size is exceeded; - the file format is not allowed;
Types ¶
type RequestError ¶
func (*RequestError) BadRequest ¶
func (r *RequestError) BadRequest() bool
func (*RequestError) Error ¶
func (r *RequestError) Error() string
func (*RequestError) InternalServerError ¶
func (r *RequestError) InternalServerError() bool
func (*RequestError) ServiceUnavailable ¶
func (r *RequestError) ServiceUnavailable() bool