85eaa3ea37
Critical: - Replace DISPATCH_TIME_FOREVER with 120s/30s timeouts in ObjC - Log failed asset IDs and error messages in cmdExport/backupTree - Show failed count in export summaries Cleanup: - Remove legacy Bridge methods (ExportAlbumPreviews, ExportAlbumOriginals, BackupAll) - Remove legacy ObjC functions and C stub equivalents - Remove photos.go delegates (package-level pass-throughs) - Remove InterpretExportResult (only used by legacy methods) - Clean up mockBridge fields (rename Fn2 -> Fn) - Fix rc race condition in main_main.go (atomic.Int32) - Remove unused variables (_ = grandTotal, _ = sig) Design: - Fix resolveAlbumID: ListAlbums first (cheap), then direct ID - Unify Cloud type: Asset.Cloud string (was bool) - Extract shared export logic into exportAssets/exportOne - Add worker pool for parallel exports (3 workers when assets >= 4) - Fix backupTree progress bar counter and directory prefix Robustness: - Add nil checks for stringWithUTF8String: in ObjC - Log directory creation errors in ensure_directory (ObjC) Quality: - Add go vet and -race flag to Makefile test target - Add ADR for performSelector cloudIdentifier decision - Add sync comments between Go/ObjC sanitizePathComponent - Add package-level doc comment - Add tests: partial failure, skipped album, album-not-found message
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
//go:build !test
|
|
|
|
package photos
|
|
|
|
/*
|
|
#cgo CFLAGS: -I${SRCDIR}/../../bridge
|
|
#cgo LDFLAGS: -L${SRCDIR}/../../bridge -lphotokit_bridge -framework Photos -framework Foundation -framework AppKit
|
|
#include "photokit_bridge.h"
|
|
#include <stdlib.h>
|
|
*/
|
|
import "C"
|
|
|
|
import "unsafe"
|
|
|
|
type CgoBridge struct{}
|
|
|
|
var DefaultBridge Bridge = &CgoBridge{}
|
|
|
|
func (*CgoBridge) RequestAccess() error {
|
|
rc := C.photos_request_access()
|
|
if rc != 0 {
|
|
return errAccessDenied
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (*CgoBridge) ListAlbums() ([]Album, error) {
|
|
cs := C.photos_list_albums_json()
|
|
if cs == nil {
|
|
return nil, errBridgeNil
|
|
}
|
|
defer C.photos_free_string(cs)
|
|
return ParseAlbumsJSON(C.GoString(cs))
|
|
}
|
|
|
|
func (*CgoBridge) ListAssets(albumID string) ([]Asset, int, error) {
|
|
cid := C.CString(albumID)
|
|
defer C.free(unsafe.Pointer(cid))
|
|
|
|
cs := C.photos_list_assets_json(cid)
|
|
if cs == nil {
|
|
return nil, 0, errBridgeNil
|
|
}
|
|
defer C.photos_free_string(cs)
|
|
return ParseAssetsJSON(C.GoString(cs))
|
|
}
|
|
|
|
func (*CgoBridge) ListTree() ([]CollectionNode, error) {
|
|
cs := C.photos_list_tree_json()
|
|
if cs == nil {
|
|
return nil, errBridgeNil
|
|
}
|
|
defer C.photos_free_string(cs)
|
|
return ParseTreeJSON(C.GoString(cs))
|
|
}
|
|
|
|
func (*CgoBridge) Cancel() {
|
|
C.photos_request_cancel()
|
|
}
|
|
|
|
func (*CgoBridge) ExportPreview(assetID, outputDir string, targetSize, index int) (ExportResult, error) {
|
|
cid := C.CString(assetID)
|
|
defer C.free(unsafe.Pointer(cid))
|
|
cdir := C.CString(outputDir)
|
|
defer C.free(unsafe.Pointer(cdir))
|
|
|
|
cs := C.photos_export_preview_json(cid, cdir, C.int(targetSize), C.int(index))
|
|
if cs == nil {
|
|
return ExportResult{}, errBridgeNil
|
|
}
|
|
defer C.photos_free_string(cs)
|
|
return ParseExportResultJSON(C.GoString(cs))
|
|
}
|
|
|
|
func (*CgoBridge) ExportOriginal(assetID, outputDir string, index int) (ExportResult, error) {
|
|
cid := C.CString(assetID)
|
|
defer C.free(unsafe.Pointer(cid))
|
|
cdir := C.CString(outputDir)
|
|
defer C.free(unsafe.Pointer(cdir))
|
|
|
|
cs := C.photos_export_original_json(cid, cdir, C.int(index))
|
|
if cs == nil {
|
|
return ExportResult{}, errBridgeNil
|
|
}
|
|
defer C.photos_free_string(cs)
|
|
return ParseExportResultJSON(C.GoString(cs))
|
|
}
|