@@ -30,7 +30,8 @@ const (
3030OffsetDateLayout = "2006-01-02T15:04:05.99999Z07:00"
3131DownloadContentFull = "full"
3232DownloadContentThumb = "thumbnail"
33- PageLimit = 100 //100 rows will make up to 100 KB
33+ MaxPageLimit = 100 //100 rows will make up to 100 KB
34+ DefaultPageLimit = 20
3435)
3536
3637type StorageHandler struct {}
@@ -782,6 +783,88 @@ func (fsh *StorageHandler) GetObjectTree(ctx context.Context, r *http.Request) (
782783return & refPathResult , nil
783784}
784785
786+ func (fsh * StorageHandler ) GetRecentlyAddedRefs (ctx context.Context , r * http.Request ) (* blobberhttp.RecentRefResult , error ) {
787+ allocationTx := ctx .Value (constants .ContextKeyAllocation ).(string )
788+ allocationObj , err := fsh .verifyAllocation (ctx , allocationTx , false )
789+
790+ if err != nil {
791+ return nil , common .NewError ("invalid_parameters" , "Invalid allocation id passed." + err .Error ())
792+ }
793+
794+ clientID := ctx .Value (constants .ContextKeyClient ).(string )
795+ if clientID == "" {
796+ return nil , common .NewError ("invalid_operation" , "Client id is required" )
797+ }
798+
799+ publicKey , _ := ctx .Value (constants .ContextKeyClientKey ).(string )
800+ if publicKey == "" {
801+ if clientID == allocationObj .OwnerID {
802+ publicKey = allocationObj .OwnerPublicKey
803+ } else {
804+ return nil , common .NewError ("empty_public_key" , "public key is required" )
805+ }
806+ }
807+
808+ clientSign := ctx .Value (constants .ContextKeyClientSignatureHeaderKey ).(string )
809+
810+ valid , err := verifySignatureFromRequest (allocationTx , clientSign , publicKey )
811+ if ! valid || err != nil {
812+ return nil , common .NewError ("invalid_signature" , "Invalid signature" )
813+ }
814+
815+ allocationID := allocationObj .ID
816+
817+ var offset , pageLimit int
818+ offsetStr := r .FormValue ("offset" )
819+
820+ if offsetStr != "" {
821+ offset , err = strconv .Atoi (offsetStr )
822+ if err != nil {
823+ return nil , common .NewError ("invalid_parameters" , "Invalid offset value " + err .Error ())
824+ }
825+ }
826+
827+ pageLimitStr := r .FormValue ("page_limit" )
828+ if pageLimitStr != "" {
829+ pageLimit , err = strconv .Atoi (pageLimitStr )
830+ if err != nil {
831+ return nil , common .NewError ("invalid_parameters" , "Invalid page limit value. Got Error " + err .Error ())
832+ }
833+ if pageLimit < 0 {
834+ return nil , common .NewError ("invalid_parameters" , "Zero/Negative page limit value is not allowed" )
835+ }
836+
837+ if pageLimit > MaxPageLimit {
838+ pageLimit = MaxPageLimit
839+ }
840+
841+ } else {
842+ pageLimit = DefaultPageLimit
843+ }
844+
845+ var fromDate int
846+ fromDateStr := r .FormValue ("from_date" )
847+ if fromDateStr != "" {
848+ fromDate , err = strconv .Atoi (fromDateStr )
849+ if err != nil {
850+ return nil , common .NewError ("invalid_parameters" , "Invalid from date value. Got error " + err .Error ())
851+ }
852+ if fromDate < 0 {
853+ return nil , common .NewError ("invalid_parameters" , "Negative from date value is not allowed" )
854+ }
855+ }
856+
857+ refs , offset , err := reference .GetRecentlyCreatedRefs (ctx , allocationID , pageLimit , offset , fromDate )
858+ if err != nil {
859+ return nil , err
860+ }
861+
862+ return & blobberhttp.RecentRefResult {
863+ Refs : refs ,
864+ Offset : offset ,
865+ }, nil
866+ }
867+
785868//Retrieves file refs. One can use three types to refer to regular, updated and deleted. Regular type gives all undeleted rows.
786869//Updated gives rows that is updated compared to the date given. And deleted gives deleted refs compared to the date given.
787870//Updated date time format should be as declared in above constant; OffsetDateLayout
@@ -886,16 +969,16 @@ func (fsh *StorageHandler) GetRefs(ctx context.Context, r *http.Request) (*blobb
886969pageLimitStr := r .FormValue ("pageLimit" )
887970var pageLimit int
888971if pageLimitStr == "" {
889- pageLimit = PageLimit
972+ pageLimit = DefaultPageLimit
890973} else {
891974o , err := strconv .Atoi (pageLimitStr )
892975if err != nil {
893976return nil , common .NewError ("invalid_parameters" , "Invalid page limit value type" )
894977}
895978if o <= 0 {
896979return nil , common .NewError ("invalid_parameters" , "Zero/Negative page limit value is not allowed" )
897- } else if o > PageLimit {
898- pageLimit = PageLimit
980+ } else if o > MaxPageLimit {
981+ pageLimit = MaxPageLimit
899982} else {
900983pageLimit = o
901984}
0 commit comments