From c30dce73dd67ba8b6aa8b07c4a184edeff1bde8b Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Fri, 16 Aug 2024 23:04:24 +0700 Subject: [PATCH] images: update proto --- schemas/proto/images/v1/images.proto | 2 + schemas/proto/images/v1/list.proto | 70 +++++++++++++++++++ .../proto/images/v1/list_by_subreddit.proto | 27 +++++++ schemas/proto/images/v1/types.proto | 40 ++++++++++- 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 schemas/proto/images/v1/list.proto diff --git a/schemas/proto/images/v1/images.proto b/schemas/proto/images/v1/images.proto index afeb4b3..a38f1bb 100644 --- a/schemas/proto/images/v1/images.proto +++ b/schemas/proto/images/v1/images.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package images.v1; +import "images/v1/list_by_subreddit.proto"; import "images/v1/recently_added.proto"; service ImageService { @@ -13,4 +14,5 @@ service ImageService { // // Maximum number of images that can be fetched at a time is 300. rpc RecentlyAddedImages(RecentlyAddedImagesRequest) returns (RecentlyAddedImagesResponse) {} + rpc ListBySubreddit(ListBySubredditRequest) returns (ListBySubredditResponse) {} } diff --git a/schemas/proto/images/v1/list.proto b/schemas/proto/images/v1/list.proto new file mode 100644 index 0000000..c1dd735 --- /dev/null +++ b/schemas/proto/images/v1/list.proto @@ -0,0 +1,70 @@ +syntax = "proto3"; + +package images.v1; + +import "buf/validate/validate.proto"; +import "images/v1/types.proto"; + +message ListImagesRequest { + option (buf.validate.message).cel = { + id: "ListBySubredditRequest.after_cannot_exist_with_before" + message: "after and before cannot be set at the same time" + expression: "this.after > 0 && this.before > 0" + }; + + // subreddits filter the images to be fetched belonging to the given subreddits names. + // + // If empty, images from all subreddits will be fetched. + string subreddit = 1 [(buf.validate.field).string.min_len = 1]; + // devices filter the images to be fetched belonging to the given devices slugs. + // + // If empty, images from all devices will be fetched. + repeated string devices = 2; + + // limit limits the number of images to be fetched. + // + // if 0 (or not set), the default limit is 25. + // + // if set, the maximum limit is clamped to 100. + int64 limit = 3 [(buf.validate.field).int64.gte = 0]; + // after lists the image after the given timestamp. + // + // using after will return images that are created after the given timestamp. + // + // cannot be set (value > 0) with before (value > 0). + int64 after = 4; + // before lists the image before the given timestamp. + // + // using before will return images that are created before the given timestamp. + // + // cannot be set (value > 0) with after (value > 0). + int64 before = 5; + + OrderBy order_by = 6; + + Sort sort = 7; + + // search searches images by text. ignored if empty. + // + // It will look up by following rank and prioritizes matches + // based on following fields: + // + // - Post Title + // - Post ID + // - Author's name + // - Author's ID + // - Image filename (url path suffix to get this image from web browser) + // - Image original url + // - Post url + // - Author's url + string search = 8; + + // nsfw filters the images to be fetched based on the nsfw flag. + NSFW nsfw = 9; +} + +message ListImagesResponse { + repeated GroupedByDeviceImages devices = 1; + optional int64 after = 2; + optional int64 before = 3; +} diff --git a/schemas/proto/images/v1/list_by_subreddit.proto b/schemas/proto/images/v1/list_by_subreddit.proto index 62dc71e..997aabc 100644 --- a/schemas/proto/images/v1/list_by_subreddit.proto +++ b/schemas/proto/images/v1/list_by_subreddit.proto @@ -6,7 +6,34 @@ import "buf/validate/validate.proto"; import "images/v1/types.proto"; message ListBySubredditRequest { + option (buf.validate.message).cel = { + id: "ListBySubredditRequest.after_cannot_exist_with_before" + message: "after and before cannot be set at the same time" + expression: "this.after > 0 && this.before > 0" + }; string subreddit = 1 [(buf.validate.field).string.min_len = 1]; + // devices filter the images to be fetched belonging to the given devices. + // + // If empty, images from all devices will be fetched. + repeated string devices = 2; + // limit limits the number of images to be fetched. + // + // if 0 (or not set), the default limit is 25. + // + // if set, the maximum limit is clamped to 100. + int64 limit = 3 [(buf.validate.field).int64.gte = 0]; + // after lists the image after the given timestamp. + // + // using after will return images that are created after the given timestamp. + // + // cannot be set (value > 0) with before (value > 0). + int64 after = 4; + // before lists the image before the given timestamp. + // + // using before will return images that are created before the given timestamp. + // + // cannot be set (value > 0) with after (value > 0). + int64 before = 5; } message ListBySubredditResponse { diff --git a/schemas/proto/images/v1/types.proto b/schemas/proto/images/v1/types.proto index dff9684..6ec41b9 100644 --- a/schemas/proto/images/v1/types.proto +++ b/schemas/proto/images/v1/types.proto @@ -13,9 +13,10 @@ message Image { string post_author_url = 8; string image_relative_path = 9; string image_original_url = 10; - uint32 image_height = 11; - uint32 image_width = 12; + int64 image_height = 11; + int64 image_width = 12; int64 image_size = 13; + bool nsfw = 14; } message GroupedByDeviceImages { @@ -28,3 +29,38 @@ message GroupedBySubredditDevices { string subreddit = 1; repeated GroupedByDeviceImages devices = 2; } + +enum OrderBy { + ORDER_BY_UNSPECIFIED = 0; + ORDER_BY_ID = 1; + ORDER_BY_SUBREDDIT = 2; + ORDER_BY_DEVICE = 3; + ORDER_BY_POST_TITLE = 4; + ORDER_BY_POST_URL = 5; + ORDER_BY_POST_CREATED = 6; + ORDER_BY_POST_AUTHOR = 7; + ORDER_BY_POST_AUTHOR_URL = 8; + ORDER_BY_IMAGE_RELATIVE_PATH = 9; + ORDER_BY_IMAGE_ORIGINAL_URL = 10; + ORDER_BY_IMAGE_HEIGHT = 11; + ORDER_BY_IMAGE_WIDTH = 12; + ORDER_BY_IMAGE_SIZE = 13; +} + +enum NSFW { + NSFW_UNSPECIFIED = 0; + NSFW_TRUE = 1; + NSFW_FALSE = 2; +} + +enum Sort { + SORT_UNSPECIFIED = 0; + SORT_ASCENDING = 1; + SORT_DESCENDING = 2; +} + +enum Blacklist { + BLACKLIST_UNSPECIFIED = 0; + BLACKLIST_TRUE = 1; + BLACKLIST_FALSE = 2; +}