Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
[Storage] Add methods to pin and unpin an upload (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
shomix authored Oct 16, 2023
1 parent ce1c097 commit ed73a48
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spheron/core",
"version": "2.0.3",
"version": "2.0.4",
"description": "Shared core package for all sdk packages",
"keywords": [
"Storage",
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/spheron-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,20 @@ class SpheronApi {
return upload;
}

async pinUpload(uploadId: string): Promise<Upload> {
const { upload } = await this.sendApiRequest<{
upload: Upload;
}>(HttpMethods.PATCH, `/v1/upload/${uploadId}/pin`);
return upload;
}

async unpinUpload(uploadId: string): Promise<Upload> {
const { upload } = await this.sendApiRequest<{
upload: Upload;
}>(HttpMethods.PATCH, `/v1/upload/${uploadId}/unpin`);
return upload;
}

//#region Upload API

private async sendApiRequest<T>(
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<p align="center">
<a href="https://www.npmjs.com/package/@spheron/storage" target="_blank" rel="noreferrer">
<img src="https://img.shields.io/static/v1?label=npm&message=v2.0.2&color=green" />
<img src="https://img.shields.io/static/v1?label=npm&message=v2.0.3&color=green" />
</a>
<a href="https://github.com/spheronFdn/sdk/blob/main/LICENSE" target="_blank" rel="noreferrer">
<img src="https://img.shields.io/static/v1?label=license&message=Apache%202.0&color=red" />
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spheron/storage",
"version": "2.0.2",
"version": "2.0.3",
"description": "Typescript library for uploading files or directory to IPFS, Filecoin or Arweave via Spheron",
"keywords": [
"Storage",
Expand Down Expand Up @@ -35,7 +35,7 @@
"dist/"
],
"dependencies": {
"@spheron/core": "2.0.3",
"@spheron/core": "2.0.4",
"@spheron/encryption": "1.0.0",
"form-data": "^4.0.0",
"multiformats": "^9.9.0"
Expand Down
10 changes: 10 additions & 0 deletions packages/storage/src/bucket-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ class BucketManager {
return this.mapCoreUpload(upload);
}

async pinUpload(uploadId: string): Promise<Upload> {
const upload = await this.spheronApi.pinUpload(uploadId);
return this.mapCoreUpload(upload);
}

async unpinUpload(uploadId: string): Promise<Upload> {
const upload = await this.spheronApi.unpinUpload(uploadId);
return this.mapCoreUpload(upload);
}

async getBucketIpnsRecords(bucketId: string): Promise<IpnsRecord[]> {
const { ipnsRecords } = await this.spheronApi.getBucketIpnsRecords(
bucketId
Expand Down
16 changes: 14 additions & 2 deletions packages/storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,18 @@ export class SpheronClient extends ScopeExtractor {
return await this.bucketManager.getUpload(uploadId);
}

async pinUpload(uploadId: string): Promise<Upload> {
await this.validateStorageOrganizationType();

return await this.bucketManager.pinUpload(uploadId);
}

async unpinUpload(uploadId: string): Promise<Upload> {
await this.validateStorageOrganizationType();

return await this.bucketManager.unpinUpload(uploadId);
}

async getOrganizationUsage(organizationId: string): Promise<UsageWithLimits> {
await this.validateStorageOrganizationType();

Expand Down Expand Up @@ -597,7 +609,7 @@ export class SpheronClient extends ScopeExtractor {
}

async migrateStaticSiteOrgToStorage(
webappOrganizationId: string,
staticSiteOrganizationId: string,
storageOrganizationId: string
): Promise<{
numberOfBuckets: number;
Expand All @@ -606,7 +618,7 @@ export class SpheronClient extends ScopeExtractor {
await this.validateStorageOrganizationType();

return await this.spheronApi.migrateStaticSiteOrgToStorage(
webappOrganizationId,
staticSiteOrganizationId,
storageOrganizationId
);
}
Expand Down

0 comments on commit ed73a48

Please sign in to comment.