minor cleanup
This commit is contained in:
@@ -40,11 +40,9 @@ func uploadToImmich(filePath, appID, baseURL, apiKey, deviceID string) (*uploadR
|
||||
return nil, fmt.Errorf("stat file: %w", err)
|
||||
}
|
||||
|
||||
// Create multipart form
|
||||
var body bytes.Buffer
|
||||
writer := multipart.NewWriter(&body)
|
||||
|
||||
// Attach the image file
|
||||
part, err := writer.CreateFormFile("assetData", filepath.Base(filePath))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create form file: %w", err)
|
||||
@@ -54,9 +52,8 @@ func uploadToImmich(filePath, appID, baseURL, apiKey, deviceID string) (*uploadR
|
||||
}
|
||||
|
||||
modTime := fileInfo.ModTime().UTC().Format(time.RFC3339)
|
||||
createTime := modTime // If you don't have a separate created time
|
||||
createTime := modTime
|
||||
|
||||
// Required metadata fields
|
||||
writer.WriteField("deviceAssetId", fmt.Sprintf("%s-%s", appID, filepath.Base(filePath)))
|
||||
writer.WriteField("deviceId", deviceID)
|
||||
writer.WriteField("fileCreatedAt", createTime)
|
||||
@@ -65,7 +62,6 @@ func uploadToImmich(filePath, appID, baseURL, apiKey, deviceID string) (*uploadR
|
||||
|
||||
writer.Close()
|
||||
|
||||
// Build request
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s/api/assets", baseURL), &body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create request: %w", err)
|
||||
@@ -88,7 +84,7 @@ func uploadToImmich(filePath, appID, baseURL, apiKey, deviceID string) (*uploadR
|
||||
|
||||
var result uploadResponse
|
||||
if err := json.Unmarshal(respBody, &result); err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse immich response: %s", err)
|
||||
return nil, fmt.Errorf("parse immich response: %s", err)
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
@@ -139,13 +135,13 @@ func addAssetsToAlbum(assets []string, album, baseURL, apiKey string) error {
|
||||
defer res.Body.Close()
|
||||
|
||||
respBody, _ := io.ReadAll(res.Body)
|
||||
if res.StatusCode >= 300 {
|
||||
return fmt.Errorf("Failed to add assets to album (%d): %s", res.StatusCode, string(respBody))
|
||||
if res.StatusCode != 200 {
|
||||
return fmt.Errorf("add assets to album (%d): %s", res.StatusCode, string(respBody))
|
||||
}
|
||||
|
||||
var result []bulkIdResponseDto
|
||||
if err := json.Unmarshal(respBody, &result); err != nil {
|
||||
return fmt.Errorf("Failed to parse immich response: %s", err)
|
||||
return fmt.Errorf("parse immich response: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user