@@ -12,11 +12,11 @@ type Entity struct {
|
||||
DecryptionHeader string `json:"decryptionHeader"`
|
||||
}
|
||||
|
||||
type IndexDiffRequest struct {
|
||||
LastUpdated int64 `form:"lastUpdated" binding:"required"`
|
||||
type FDDiffRequest struct {
|
||||
LastUpdatedAt *int64 `form:"lastUpdated" binding:"required"`
|
||||
}
|
||||
|
||||
type IndexStatus struct {
|
||||
type FDStatus struct {
|
||||
FileID int64 `json:"fileID" binding:"required"`
|
||||
UserID int64 `json:"userID" binding:"required"`
|
||||
Type ente.ObjectType `json:"type" binding:"required"`
|
||||
|
||||
@@ -51,17 +51,23 @@ func (h *FileHandler) GetFilesData(ctx *gin.Context) {
|
||||
// FileDataStatusDiff API won't really return status/diff for deleted files. The clients will primarily use this data to identify for which all files we already have preview generated or it's ML inference is done.
|
||||
// This doesn't simulate perfect diff behaviour as we won't maintain a tombstone entries for the deleted API.
|
||||
func (h *FileHandler) FileDataStatusDiff(ctx *gin.Context) {
|
||||
var req fileData.IndexDiffRequest
|
||||
var req fileData.FDDiffRequest
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, ente.NewBadRequestWithMessage(err.Error()))
|
||||
return
|
||||
}
|
||||
resp, err := h.FileDataCtrl.FileDataStatusDiff(ctx, req)
|
||||
if req.LastUpdatedAt == nil || *req.LastUpdatedAt < 0 {
|
||||
ctx.JSON(http.StatusBadRequest, ente.NewBadRequestWithMessage("lastUpdated is required and should be greater than or equal to 0"))
|
||||
return
|
||||
}
|
||||
diff, err := h.FileDataCtrl.FileDataStatusDiff(ctx, req)
|
||||
if err != nil {
|
||||
handler.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"diff": diff,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *FileHandler) GetFileData(ctx *gin.Context) {
|
||||
|
||||
@@ -314,7 +314,7 @@ func (c *Controller) _validatePermission(ctx *gin.Context, fileID int64, actorID
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Controller) FileDataStatusDiff(ctx *gin.Context, req fileData.IndexDiffRequest) ([]fileData.IndexStatus, error) {
|
||||
func (c *Controller) FileDataStatusDiff(ctx *gin.Context, req fileData.FDDiffRequest) ([]fileData.FDStatus, error) {
|
||||
userID := auth.GetUserID(ctx.Request.Header)
|
||||
return c.Repo.GetIndexStatusForUser(ctx, userID, req.LastUpdated, 5000)
|
||||
return c.Repo.GetFDForUser(ctx, userID, *req.LastUpdatedAt, 5000)
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func (r *Repository) RemoveBucket(row filedata.Row, bucketID string, columnName
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) GetIndexStatusForUser(ctx context.Context, userID int64, lastUpdatedAt int64, limit int64) ([]filedata.IndexStatus, error) {
|
||||
func (r *Repository) GetFDForUser(ctx context.Context, userID int64, lastUpdatedAt int64, limit int64) ([]filedata.FDStatus, error) {
|
||||
rows, err := r.DB.QueryContext(ctx, `SELECT file_id, user_id, data_type, size, is_deleted, updated_at
|
||||
FROM file_data
|
||||
WHERE user_id = $1 AND updated_at > $2 ORDER BY updated_at
|
||||
@@ -134,16 +134,16 @@ func (r *Repository) GetIndexStatusForUser(ctx context.Context, userID int64, la
|
||||
if err != nil {
|
||||
return nil, stacktrace.Propagate(err, "")
|
||||
}
|
||||
var indexStatuses []filedata.IndexStatus
|
||||
var fdStatuses []filedata.FDStatus
|
||||
for rows.Next() {
|
||||
var indexStatus filedata.IndexStatus
|
||||
scanErr := rows.Scan(&indexStatus.FileID, &indexStatus.UserID, &indexStatus.Type, &indexStatus.Size, &indexStatus.IsDeleted, &indexStatus.UpdatedAt)
|
||||
var status filedata.FDStatus
|
||||
scanErr := rows.Scan(&status.FileID, &status.UserID, &status.Type, &status.Size, &status.IsDeleted, &status.UpdatedAt)
|
||||
if scanErr != nil {
|
||||
return nil, stacktrace.Propagate(scanErr, "")
|
||||
}
|
||||
indexStatuses = append(indexStatuses, indexStatus)
|
||||
fdStatuses = append(fdStatuses, status)
|
||||
}
|
||||
return indexStatuses, nil
|
||||
return fdStatuses, nil
|
||||
}
|
||||
|
||||
func (r *Repository) MoveBetweenBuckets(row filedata.Row, bucketID string, sourceColumn string, destColumn string) error {
|
||||
|
||||
Reference in New Issue
Block a user