-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a00c4c5
commit 0d1b71f
Showing
7 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Service, ServiceProperties } from './service'; | ||
import { FileAPI } from '../api'; | ||
import invariant from 'tiny-invariant'; | ||
import { Buffer } from 'buffer'; | ||
|
||
interface FileServiceProperties {} | ||
|
||
type FileServiceParameters = ServiceProperties & FileServiceProperties; | ||
|
||
export class FileService extends Service implements FileServiceProperties { | ||
/** | ||
* Instantiate the election service. | ||
* | ||
* @param {Partial<FileServiceParameters>} params The service parameters | ||
*/ | ||
constructor(params: Partial<FileServiceParameters>) { | ||
super(); | ||
Object.assign(this, params); | ||
} | ||
|
||
/** | ||
* Fetches the CID expected for the specified data content. | ||
* | ||
* @param {string} data The data of which we want the CID of | ||
* @returns {Promise<string>} Resulting CID | ||
*/ | ||
calculateCID(data: string): Promise<string> { | ||
invariant(this.url, 'No URL set'); | ||
const b64Data = Buffer.from(data, 'utf8').toString('base64'); | ||
return FileAPI.cid(this.url, b64Data).then((response) => response.cid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters