renamed some structs to make the private
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func hashFiles(assets []AssetState) (map[int]string, error) {
|
func hashFiles(assets []assetState) (map[int]string, error) {
|
||||||
results := make(map[int]string)
|
results := make(map[int]string)
|
||||||
|
|
||||||
for i, p := range assets {
|
for i, p := range assets {
|
||||||
|
|||||||
@@ -41,18 +41,18 @@ type assetBulkUploadCheckResult struct {
|
|||||||
Reason string // can be "duplicate" or "unsupportedFormat" (i don't know what they mean by this)
|
Reason string // can be "duplicate" or "unsupportedFormat" (i don't know what they mean by this)
|
||||||
}
|
}
|
||||||
|
|
||||||
type APIKeyTransport struct {
|
type apiKeyTransport struct {
|
||||||
APIKey string
|
APIKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *APIKeyTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (t *apiKeyTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
req = req.Clone(req.Context())
|
req = req.Clone(req.Context())
|
||||||
req.Header.Add("x-api-key", t.APIKey)
|
req.Header.Add("x-api-key", t.APIKey)
|
||||||
return http.DefaultTransport.RoundTrip(req)
|
return http.DefaultTransport.RoundTrip(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImmichHttpClient(apiKey string) http.Client {
|
func newImmichHttpClient(apiKey string) http.Client {
|
||||||
transport := APIKeyTransport{
|
transport := apiKeyTransport{
|
||||||
APIKey: apiKey,
|
APIKey: apiKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,21 +7,21 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AssetState struct {
|
type assetState struct {
|
||||||
FilePath string
|
FilePath string
|
||||||
ImmichID string
|
ImmichID string
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalState struct {
|
type localState struct {
|
||||||
Assets []AssetState
|
Assets []assetState
|
||||||
GameIDs map[string]string
|
GameIDs map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadLocalState(filename string) (*LocalState, error) {
|
func loadLocalState(filename string) (*localState, error) {
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
return &LocalState{Assets: []AssetState{}, GameIDs: map[string]string{}}, nil
|
return &localState{Assets: []assetState{}, GameIDs: map[string]string{}}, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ func loadLocalState(filename string) (*LocalState, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var data LocalState
|
var data localState
|
||||||
err = json.Unmarshal(content, &data)
|
err = json.Unmarshal(content, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -40,7 +40,7 @@ func loadLocalState(filename string) (*LocalState, error) {
|
|||||||
return &data, nil
|
return &data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveLocalState(filename string, state LocalState) error {
|
func saveLocalState(filename string, state localState) error {
|
||||||
content, err := json.Marshal(state)
|
content, err := json.Marshal(state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
const UNKOWN_GAME_GAME = "Unkown"
|
const UNKOWN_GAME_GAME = "Unkown"
|
||||||
|
|
||||||
type SteamAPIResponse struct {
|
type steamAPIResponse struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Data struct {
|
Data struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -46,7 +46,7 @@ func fetchGameName(appID string) (string, error) {
|
|||||||
return "", fmt.Errorf("reading response for %s: %s", appID, err)
|
return "", fmt.Errorf("reading response for %s: %s", appID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var result map[string]SteamAPIResponse
|
var result map[string]steamAPIResponse
|
||||||
if err := json.Unmarshal(body, &result); err != nil {
|
if err := json.Unmarshal(body, &result); err != nil {
|
||||||
return "", fmt.Errorf("parsing response for %s: %s", appID, err)
|
return "", fmt.Errorf("parsing response for %s: %s", appID, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func Run(config Config) {
|
|||||||
|
|
||||||
for _, filepath := range files {
|
for _, filepath := range files {
|
||||||
|
|
||||||
idx := slices.IndexFunc(localState.Assets, func(e AssetState) bool { return e.FilePath == filepath })
|
idx := slices.IndexFunc(localState.Assets, func(e assetState) bool { return e.FilePath == filepath })
|
||||||
|
|
||||||
if idx != -1 {
|
if idx != -1 {
|
||||||
log.Printf("Asset already uploaded: %s", filepath)
|
log.Printf("Asset already uploaded: %s", filepath)
|
||||||
@@ -59,7 +59,7 @@ func Run(config Config) {
|
|||||||
|
|
||||||
log.Printf("Assest uploaded: %s (%s) %s with ID: %s", gameName, appid, filepath, res.ID)
|
log.Printf("Assest uploaded: %s (%s) %s with ID: %s", gameName, appid, filepath, res.ID)
|
||||||
|
|
||||||
localState.Assets = append(localState.Assets, AssetState{FilePath: filepath, ImmichID: res.ID})
|
localState.Assets = append(localState.Assets, assetState{FilePath: filepath, ImmichID: res.ID})
|
||||||
|
|
||||||
assetsInGame = append(assetsInGame, res.ID)
|
assetsInGame = append(assetsInGame, res.ID)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user