Skip to content

Commit

Permalink
chore: rename to segmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Aug 7, 2024
1 parent c404c62 commit bf7cb9b
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 148 deletions.
6 changes: 3 additions & 3 deletions api/model/snapshot_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Snapshot interface {
GetOCR() *S3Object
GetEntities() *S3Object
GetMosaic() *S3Object
GetMobile() *S3Object
GetSegmentation() *S3Object
GetThumbnail() *S3Object
GetTaskID() *string
HasOriginal() bool
Expand All @@ -35,7 +35,7 @@ type Snapshot interface {
HasOCR() bool
HasEntities() bool
HasMosaic() bool
HasMobile() bool
HasSegmentation() bool
HasThumbnail() bool
GetStatus() string
GetLanguage() *string
Expand All @@ -49,7 +49,7 @@ type Snapshot interface {
SetOCR(*S3Object)
SetEntities(*S3Object)
SetMosaic(*S3Object)
SetMobile(*S3Object)
SetSegmentation(*S3Object)
SetThumbnail(*S3Object)
SetStatus(string)
SetLanguage(string)
Expand Down
96 changes: 48 additions & 48 deletions api/repo/snapshot_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ func NewSnapshot() model.Snapshot {
}

type snapshotEntity struct {
ID string `gorm:"column:id;size:36" json:"id"`
Version int64 `gorm:"column:version" json:"version"`
Original datatypes.JSON `gorm:"column:original" json:"original,omitempty"`
Preview datatypes.JSON `gorm:"column:preview" json:"preview,omitempty"`
Text datatypes.JSON `gorm:"column:text" json:"text,omitempty"`
OCR datatypes.JSON `gorm:"column:ocr" json:"ocr,omitempty"`
Entities datatypes.JSON `gorm:"column:entities" json:"entities,omitempty"`
Mosaic datatypes.JSON `gorm:"column:mosaic" json:"mosaic,omitempty"`
Mobile datatypes.JSON `gorm:"column:mobile" json:"mobile,omitempty"`
Thumbnail datatypes.JSON `gorm:"column:thumbnail" json:"thumbnail,omitempty"`
Status string `gorm:"column,status" json:"status,omitempty"`
Language *string `gorm:"column:language" json:"language,omitempty"`
TaskID *string `gorm:"column:task_id" json:"taskId,omitempty"`
CreateTime string `gorm:"column:create_time" json:"createTime"`
UpdateTime *string `gorm:"column:update_time" json:"updateTime,omitempty"`
ID string `gorm:"column:id;size:36" json:"id"`
Version int64 `gorm:"column:version" json:"version"`
Original datatypes.JSON `gorm:"column:original" json:"original,omitempty"`
Preview datatypes.JSON `gorm:"column:preview" json:"preview,omitempty"`
Text datatypes.JSON `gorm:"column:text" json:"text,omitempty"`
OCR datatypes.JSON `gorm:"column:ocr" json:"ocr,omitempty"`
Entities datatypes.JSON `gorm:"column:entities" json:"entities,omitempty"`
Mosaic datatypes.JSON `gorm:"column:mosaic" json:"mosaic,omitempty"`
Segmentation datatypes.JSON `gorm:"column:segmentation" json:"segmentation,omitempty"`
Thumbnail datatypes.JSON `gorm:"column:thumbnail" json:"thumbnail,omitempty"`
Status string `gorm:"column,status" json:"status,omitempty"`
Language *string `gorm:"column:language" json:"language,omitempty"`
TaskID *string `gorm:"column:task_id" json:"taskId,omitempty"`
CreateTime string `gorm:"column:create_time" json:"createTime"`
UpdateTime *string `gorm:"column:update_time" json:"updateTime,omitempty"`
}

func (*snapshotEntity) TableName() string {
Expand Down Expand Up @@ -168,12 +168,12 @@ func (s *snapshotEntity) GetMosaic() *model.S3Object {
return &res
}

func (s *snapshotEntity) GetMobile() *model.S3Object {
if s.Mobile.String() == "" {
func (s *snapshotEntity) GetSegmentation() *model.S3Object {
if s.Segmentation.String() == "" {
return nil
}
res := model.S3Object{}
if err := json.Unmarshal([]byte(s.Mobile.String()), &res); err != nil {
if err := json.Unmarshal([]byte(s.Segmentation.String()), &res); err != nil {
log.GetLogger().Fatal(err)
return nil
}
Expand Down Expand Up @@ -302,16 +302,16 @@ func (s *snapshotEntity) SetMosaic(m *model.S3Object) {
}
}

func (s *snapshotEntity) SetMobile(m *model.S3Object) {
func (s *snapshotEntity) SetSegmentation(m *model.S3Object) {
if m == nil {
s.Mobile = nil
s.Segmentation = nil
} else {
b, err := json.Marshal(m)
if err != nil {
log.GetLogger().Fatal(err)
return
}
if err := s.Mobile.UnmarshalJSON(b); err != nil {
if err := s.Segmentation.UnmarshalJSON(b); err != nil {
log.GetLogger().Fatal(err)
}
}
Expand Down Expand Up @@ -368,8 +368,8 @@ func (s *snapshotEntity) HasMosaic() bool {
return s.Mosaic != nil
}

func (s *snapshotEntity) HasMobile() bool {
return s.Mobile != nil
func (s *snapshotEntity) HasSegmentation() bool {
return s.Segmentation != nil
}

func (s *snapshotEntity) HasThumbnail() bool {
Expand Down Expand Up @@ -468,32 +468,32 @@ func (repo *snapshotRepo) Delete(id string) error {
}

type SnapshotUpdateOptions struct {
Fields []string `json:"fields"`
Original *model.S3Object
Preview *model.S3Object
Text *model.S3Object
OCR *model.S3Object
Entities *model.S3Object
Mosaic *model.S3Object
Mobile *model.S3Object
Thumbnail *model.S3Object
Status *string
Language *string
TaskID *string
Fields []string `json:"fields"`
Original *model.S3Object
Preview *model.S3Object
Text *model.S3Object
OCR *model.S3Object
Entities *model.S3Object
Mosaic *model.S3Object
Segmentation *model.S3Object
Thumbnail *model.S3Object
Status *string
Language *string
TaskID *string
}

const (
SnapshotFieldOriginal = "original"
SnapshotFieldPreview = "preview"
SnapshotFieldText = "text"
SnapshotFieldOCR = "ocr"
SnapshotFieldEntities = "entities"
SnapshotFieldMosaic = "mosaic"
SnapshotFieldMobile = "mobile"
SnapshotFieldThumbnail = "thumbnail"
SnapshotFieldStatus = "status"
SnapshotFieldLanguage = "language"
SnapshotFieldTaskID = "taskId"
SnapshotFieldOriginal = "original"
SnapshotFieldPreview = "preview"
SnapshotFieldText = "text"
SnapshotFieldOCR = "ocr"
SnapshotFieldEntities = "entities"
SnapshotFieldMosaic = "mosaic"
SnapshotFieldSegmentation = "segmentation"
SnapshotFieldThumbnail = "thumbnail"
SnapshotFieldStatus = "status"
SnapshotFieldLanguage = "language"
SnapshotFieldTaskID = "taskId"
)

func (repo *snapshotRepo) Update(id string, opts SnapshotUpdateOptions) error {
Expand All @@ -519,8 +519,8 @@ func (repo *snapshotRepo) Update(id string, opts SnapshotUpdateOptions) error {
if slices.Contains(opts.Fields, SnapshotFieldMosaic) {
snapshot.SetMosaic(opts.Mosaic)
}
if slices.Contains(opts.Fields, SnapshotFieldMobile) {
snapshot.SetMobile(opts.Mobile)
if slices.Contains(opts.Fields, SnapshotFieldSegmentation) {
snapshot.SetSegmentation(opts.Segmentation)
}
if slices.Contains(opts.Fields, SnapshotFieldThumbnail) {
snapshot.SetThumbnail(opts.Thumbnail)
Expand Down
32 changes: 16 additions & 16 deletions api/router/file_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (r *FileRouter) AppendNonJWTRoutes(g fiber.Router) {
g.Get("/:id/original:ext", r.DownloadOriginal)
g.Get("/:id/preview:ext", r.DownloadPreview)
g.Get("/:id/thumbnail:ext", r.DownloadThumbnail)
g.Get("/:id/mobile/pages/:page.pdf", r.DownloadMobilePage)
g.Get("/:id/mobile/thumbnails/:page.png", r.DownloadMobileThumbnail)
g.Get("/:id/segmentation/pages/:page.pdf", r.DownloadSegmentationPage)
g.Get("/:id/segmentation/thumbnails/:page.png", r.DownloadSegmentationThumbnail)
g.Post("/create_from_s3", r.CreateFromS3)
g.Patch("/:id/patch_from_s3", r.PatchFromS3)
}
Expand Down Expand Up @@ -984,20 +984,20 @@ func (r *FileRouter) DownloadThumbnail(c *fiber.Ctx) error {
return c.Send(b)
}

// DownloadMobilePage godoc
// DownloadSegmentationPage godoc
//
// @Summary Download Mobile Page
// @Description Download Mobile Page
// @Summary Download Segmentation Page
// @Description Download Segmentation Page
// @Tags Files
// @Id files_download_mobile_page
// @Id files_download_segmentation_page
// @Produce json
// @Param id path string true "ID"
// @Param page path string true "Page"
// @Param access_token query string true "Access Token"
// @Failure 404 {object} errorpkg.ErrorResponse
// @Failure 500 {object} errorpkg.ErrorResponse
// @Router /files/{id}/mobile/pages/{page}.png [get]
func (r *FileRouter) DownloadMobilePage(c *fiber.Ctx) error {
// @Router /files/{id}/segmentation/pages/{page}.png [get]
func (r *FileRouter) DownloadSegmentationPage(c *fiber.Ctx) error {
accessToken := c.Cookies(r.accessTokenCookieName)
if accessToken == "" {
accessToken = c.Query("access_token")
Expand All @@ -1017,7 +1017,7 @@ func (r *FileRouter) DownloadMobilePage(c *fiber.Ctx) error {
if err != nil {
return errorpkg.NewInvalidQueryParamError("page")
}
buf, file, err := r.fileSvc.DownloadMobilePageBuffer(id, page, userID)
buf, file, err := r.fileSvc.DownloadSegmentationPageBuffer(id, page, userID)
if err != nil {
return err
}
Expand All @@ -1027,20 +1027,20 @@ func (r *FileRouter) DownloadMobilePage(c *fiber.Ctx) error {
return c.Send(b)
}

// DownloadMobileThumbnail godoc
// DownloadSegmentationThumbnail godoc
//
// @Summary Download Mobile Thumbnail
// @Description Download Mobile Thumbnail
// @Summary Download Segmentation Thumbnail
// @Description Download Segmentation Thumbnail
// @Tags Files
// @Id files_download_mobile_thumbnail
// @Id files_download_segmentation_thumbnail
// @Produce json
// @Param id path string true "ID"
// @Param page path string true "Page"
// @Param access_token query string true "Access Token"
// @Failure 404 {object} errorpkg.ErrorResponse
// @Failure 500 {object} errorpkg.ErrorResponse
// @Router /files/{id}/mobile/thumbnails/{page}.png [get]
func (r *FileRouter) DownloadMobileThumbnail(c *fiber.Ctx) error {
// @Router /files/{id}/segmentation/thumbnails/{page}.png [get]
func (r *FileRouter) DownloadSegmentationThumbnail(c *fiber.Ctx) error {
accessToken := c.Cookies(r.accessTokenCookieName)
if accessToken == "" {
accessToken = c.Query("access_token")
Expand All @@ -1060,7 +1060,7 @@ func (r *FileRouter) DownloadMobileThumbnail(c *fiber.Ctx) error {
if err != nil {
return errorpkg.NewInvalidQueryParamError("page")
}
buf, file, err := r.fileSvc.DownloadMobileThumbnailBuffer(id, page, userID)
buf, file, err := r.fileSvc.DownloadSegmentationThumbnailBuffer(id, page, userID)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions api/service/file_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (svc *FileService) DownloadThumbnailBuffer(id string, userID string) (*byte
}
}

func (svc *FileService) DownloadMobilePageBuffer(id string, page int, userID string) (*bytes.Buffer, model.File, error) {
func (svc *FileService) DownloadSegmentationPageBuffer(id string, page int, userID string) (*bytes.Buffer, model.File, error) {
file, err := svc.fileCache.Get(id)
if err != nil {
return nil, nil, err
Expand All @@ -441,8 +441,8 @@ func (svc *FileService) DownloadMobilePageBuffer(id string, page int, userID str
if err != nil {
return nil, nil, err
}
if snapshot.HasMobile() {
buf, _, err := svc.s3.GetObject(filepath.FromSlash(snapshot.GetMobile().Key+fmt.Sprintf("/pages/%d.pdf", page)), snapshot.GetMobile().Bucket, minio.GetObjectOptions{})
if snapshot.HasSegmentation() {
buf, _, err := svc.s3.GetObject(filepath.FromSlash(snapshot.GetSegmentation().Key+fmt.Sprintf("/pages/%d.pdf", page)), snapshot.GetSegmentation().Bucket, minio.GetObjectOptions{})
if err != nil {
return nil, nil, err
}
Expand All @@ -452,7 +452,7 @@ func (svc *FileService) DownloadMobilePageBuffer(id string, page int, userID str
}
}

func (svc *FileService) DownloadMobileThumbnailBuffer(id string, page int, userID string) (*bytes.Buffer, model.File, error) {
func (svc *FileService) DownloadSegmentationThumbnailBuffer(id string, page int, userID string) (*bytes.Buffer, model.File, error) {
file, err := svc.fileCache.Get(id)
if err != nil {
return nil, nil, err
Expand All @@ -467,8 +467,8 @@ func (svc *FileService) DownloadMobileThumbnailBuffer(id string, page int, userI
if err != nil {
return nil, nil, err
}
if snapshot.HasMobile() {
buf, _, err := svc.s3.GetObject(filepath.FromSlash(snapshot.GetMobile().Key+fmt.Sprintf("/thumbnails/%d.png", page)), snapshot.GetMobile().Bucket, minio.GetObjectOptions{})
if snapshot.HasSegmentation() {
buf, _, err := svc.s3.GetObject(filepath.FromSlash(snapshot.GetSegmentation().Key+fmt.Sprintf("/thumbnails/%d.png", page)), snapshot.GetSegmentation().Bucket, minio.GetObjectOptions{})
if err != nil {
return nil, nil, err
}
Expand Down
Loading

0 comments on commit bf7cb9b

Please sign in to comment.