gimmich

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 1cc5be0fcf43873a6f64deacfad4e7ebfed280f7
parent 340692a4b87a4e21e5091954bba17cdc785d8354
Author: Martin Ashby <martin@ashbysoft.com>
Date:   Thu,  1 Oct 2026 22:08:05 +0100

More noddy implementation

Remove auth checks for now.

Diffstat:
Mmain.go | 109++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Munimplemented.go | 29-----------------------------
2 files changed, 97 insertions(+), 41 deletions(-)

diff --git a/main.go b/main.go @@ -2,10 +2,12 @@ package main import ( "encoding/json" + "io" "log" "log/slog" "net/http" "strconv" + "time" "database/sql" "os" @@ -20,9 +22,16 @@ import ( const ( address = "127.0.0.1:8080" api = "/api" + email = "martin@mfashby.net" + name = "Martin Ashby" +) + +var ( + userid = must(func() (uuid.UUID, error) { return uuid.Parse("8e251dd2-2d10-484b-bdc3-0128d855f204") }) ) func main() { + _ = must(func() (time.Time, error) { return time.Parse(time.RFC3339, "2026-09-28T12:00:00Z")} ) db, err := sql.Open("sqlite3", "gimmich.db") if err != nil { slog.Error("error opening database", "err", err.Error()) @@ -115,29 +124,55 @@ type MyServer struct{ // Login implements [ServerInterface]. func (m *MyServer) Login(w http.ResponseWriter, r *http.Request) { - lrb, err := doReadJsonRequestOrSendErr(w, r, &LoginJSONRequestBody{}) + /*lrb*/_, err := doReadJsonRequestOrSendErr(w, r, &LoginJSONRequestBody{}) if err != nil { return } - if lrb.Email == "martin@mfashby.net" && lrb.Password == "P@55word" { - u := must(func() (uuid.UUID, error) { return uuid.Parse("8e251dd2-2d10-484b-bdc3-0128d855f204") }) + // TODO comment back in auth check + // if lrb.Email == email && lrb.Password == "P@55word" { + doWriteJsonResponse(w, LoginResponseDto{ AccessToken: "foobar", IsAdmin: true, IsOnboarded: true, - Name: "Martin Ashby", + Name: name, ProfileImagePath: "", ShouldChangePassword: false, - UserEmail: "martin@mfashby.net", - UserId: u, - }) - } else { - w.WriteHeader(401) - doWriteResponse(w, func(w http.ResponseWriter) error { - _, e := w.Write([]byte("unauthorized")) - return e + UserEmail: email, + UserId: userid, }) + // } else { + // w.WriteHeader(401) + // doWriteResponse(w, func(w http.ResponseWriter) error { + // _, e := w.Write([]byte("unauthorized")) + // return e + // }) + // } +} + +// Logout implements [ServerInterface]. +func (m *MyServer) Logout(w http.ResponseWriter, r *http.Request) { + doWriteJsonResponse(w, LogoutResponseDto{ + RedirectUri: "/auth/login", + Successful: true, + }) +} + +// ValidateAccessToken implements [ServerInterface]. +func (m *MyServer) ValidateAccessToken(w http.ResponseWriter, r *http.Request) { + bytes, err := io.ReadAll(r.Body) + if err != nil { + slog.Error("ValidateAccessToken", slog.Any("err", err)) + serverError(w) + return + } + for k, v := range r.Header { + slog.Info("ValidateAccessToken", slog.String("key", k), slog.Any("value", v)) } + slog.Info("ValidateAccessToken", slog.String("body", string(bytes))) + doWriteJsonResponse(w, ValidateAccessTokenResponseDto{ + AuthStatus: true, + }) } // PingServer implements [ServerInterface]. @@ -200,3 +235,53 @@ func (m *MyServer) GetServerConfig(w http.ResponseWriter, r *http.Request) { UserDeleteDelay: 0, }) } + +// GetMyUser implements [ServerInterface]. +func (m *MyServer) GetMyUser(w http.ResponseWriter, r *http.Request) { + quotasizebytes := 10_000_000_000 + quotausagebytes := 1_000_000_000 + created := must(func() (time.Time, error) { return time.Parse(time.RFC3339, "2026-09-28T12:00:00Z")} ) + doWriteJsonResponse(w, UserAdminResponseDto{ + AvatarColor: "blue", + CreatedAt: created, + DeletedAt: nil, + Email: email, + Id: userid, + IsAdmin: false, + License: nil, + Name: name, + OauthId: "", + ProfileChangedAt: time.Time{}, + ProfileImagePath: "", + QuotaSizeInBytes: &quotasizebytes, + QuotaUsageInBytes: &quotausagebytes, + ShouldChangePassword: false, + Status: "active", + StorageLabel: nil, + UpdatedAt: created, + }) +} + +// GetMyPreferences implements [ServerInterface]. +func (m *MyServer) GetMyPreferences(w http.ResponseWriter, r *http.Request) { + doWriteJsonResponse(w, UserPreferencesResponseDto{ + Albums: AlbumsResponse{}, + Cast: CastResponse{}, + Download: DownloadResponse{}, + EmailNotifications: EmailNotificationsResponse{}, + Folders: FoldersResponse{}, + Memories: MemoriesResponse{}, + People: PeopleResponse{}, + Purchase: PurchaseResponse{}, + Ratings: RatingsResponse{}, + RecentlyAdded: RecentlyAddedResponse{}, + SharedLinks: SharedLinksResponse{}, + Tags: TagsResponse{}, + }) +} + +// DeleteSyncAck implements [ServerInterface]. +func (m *MyServer) DeleteSyncAck(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(204) +} + diff --git a/unimplemented.go b/unimplemented.go @@ -1,7 +1,6 @@ package main import ( - "encoding/json" "github.com/oapi-codegen/runtime/types" "net/http" ) @@ -263,11 +262,6 @@ func (m *MyServer) DeleteStacks(w http.ResponseWriter, r *http.Request) { panic("unimplemented") } -// DeleteSyncAck implements [ServerInterface]. -func (m *MyServer) DeleteSyncAck(w http.ResponseWriter, r *http.Request) { - panic("unimplemented") -} - // DeleteTag implements [ServerInterface]. func (m *MyServer) DeleteTag(w http.ResponseWriter, r *http.Request, id types.UUID) { panic("unimplemented") @@ -553,24 +547,11 @@ func (m *MyServer) GetMyCalendarHeatmap(w http.ResponseWriter, r *http.Request, panic("unimplemented") } -// GetMyPreferences implements [ServerInterface]. -func (m *MyServer) GetMyPreferences(w http.ResponseWriter, r *http.Request) { - panic("unimplemented") -} - // GetMySharedLink implements [ServerInterface]. func (m *MyServer) GetMySharedLink(w http.ResponseWriter, r *http.Request, params GetMySharedLinkParams) { panic("unimplemented") } -// GetMyUser implements [ServerInterface]. -func (m *MyServer) GetMyUser(w http.ResponseWriter, r *http.Request) { - res := UserAdminResponseDto{} - doWriteResponse(w, func(w http.ResponseWriter) error { - return json.NewEncoder(w).Encode(res) - }) -} - // GetNotification implements [ServerInterface]. func (m *MyServer) GetNotification(w http.ResponseWriter, r *http.Request, id types.UUID) { panic("unimplemented") @@ -811,11 +792,6 @@ func (m *MyServer) LockSession(w http.ResponseWriter, r *http.Request, id types. panic("unimplemented") } -// Logout implements [ServerInterface]. -func (m *MyServer) Logout(w http.ResponseWriter, r *http.Request) { - panic("unimplemented") -} - // LogoutOAuth implements [ServerInterface]. func (m *MyServer) LogoutOAuth(w http.ResponseWriter, r *http.Request) { panic("unimplemented") @@ -1246,11 +1222,6 @@ func (m *MyServer) Validate(w http.ResponseWriter, r *http.Request, id types.UUI panic("unimplemented") } -// ValidateAccessToken implements [ServerInterface]. -func (m *MyServer) ValidateAccessToken(w http.ResponseWriter, r *http.Request) { - panic("unimplemented") -} - // ViewAsset implements [ServerInterface]. func (m *MyServer) ViewAsset(w http.ResponseWriter, r *http.Request, id types.UUID, params ViewAssetParams) { panic("unimplemented")