From 24c5907e541512abb4bb263dff22d61847ec7b44 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Sun, 14 Apr 2024 13:11:10 +0700 Subject: [PATCH] update libs --- api/download_subreddit_images.go | 2 +- api/reddit/post.go | 13 +++++++++++++ db/queries/devices.sql | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 db/queries/devices.sql diff --git a/api/download_subreddit_images.go b/api/download_subreddit_images.go index f934ea6..3ee0473 100644 --- a/api/download_subreddit_images.go +++ b/api/download_subreddit_images.go @@ -147,7 +147,7 @@ func (api *API) downloadSubredditImage(ctx context.Context, post reddit.Post, de return nil } if !errors.Is(errStat, os.ErrNotExist) { - return errs.Wrapw(err, "failed to check thumbail existence", "path", thumbnailPath) + return errs.Wrapw(err, "failed to check thumbnail existence", "path", thumbnailPath) } thumbnailSource, err := imaging.Open(tmpImageFile.filename) diff --git a/api/reddit/post.go b/api/reddit/post.go index 72f69d8..ff0452b 100644 --- a/api/reddit/post.go +++ b/api/reddit/post.go @@ -235,6 +235,19 @@ func (post *Post) GetThumbnailTargetPath(cfg *config.Config) string { return path.Join(baseDownloadDir, "_thumbnails", post.GetSubreddit(), post.GetImageFilename()) } +func (post *Post) GetThumbnailRelativePath() string { + return path.Join("_thumbnails", post.GetSubreddit(), post.GetImageFilename()) +} + +func (post *Post) GetImageRelativePath(device queries.Device) string { + return path.Join(device.Name, post.GetSubreddit(), post.GetImageFilename()) +} + +func (post *Post) GetWindowsWallpaperImageRelativePath(device queries.Device) string { + filename := fmt.Sprintf("%s_%s", post.GetSubreddit(), post.GetImageFilename()) + return path.Join(device.Name, filename) +} + func (post *Post) GetImageFilename() string { if !post.IsImagePost() { return "" diff --git a/db/queries/devices.sql b/db/queries/devices.sql new file mode 100644 index 0000000..02d60f6 --- /dev/null +++ b/db/queries/devices.sql @@ -0,0 +1,7 @@ +-- name: GetDevices :many +SELECT * FROM devices; + +-- name: CreateDevice :one +INSERT INTO devices (name, resolution_x, resolution_y, aspect_ratio_tolerance, min_x, min_y, max_x, max_y, nsfw, windows_wallpaper_mode) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +RETURNING *;