Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer neilan committed Nov 18, 2021
0 parents commit 46fe3ad
Show file tree
Hide file tree
Showing 14 changed files with 5,286 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .dfx/local/canister_ids.json
@@ -0,0 +1,8 @@
{
"__Candid_UI": {
"local": "sgymv-uiaaa-aaaaa-aaaia-cai"
},
"storage": {
"local": "q3fc5-haaaa-aaaaa-aaahq-cai"
}
}
38 changes: 38 additions & 0 deletions .dfx/local/canisters/storage/index.js
@@ -0,0 +1,38 @@
import { Actor, HttpAgent } from "@dfinity/agent";

// Imports and re-exports candid interface
import { idlFactory } from './storage.did.js';
export { idlFactory } from './storage.did.js';
// CANISTER_ID is replaced by webpack based on node environment
export const canisterId = process.env.STORAGE_CANISTER_ID;

/**
*
* @param {string | import("@dfinity/principal").Principal} canisterId Canister ID of Agent
* @param {{agentOptions?: import("@dfinity/agent").HttpAgentOptions; actorOptions?: import("@dfinity/agent").ActorConfig}} [options]
* @return {import("@dfinity/agent").ActorSubclass<import("./storage.did.js")._SERVICE>}
*/
export const createActor = (canisterId, options) => {
const agent = new HttpAgent({ ...options?.agentOptions });

// Fetch root key for certificate validation during development
if(process.env.NODE_ENV !== "production") {
agent.fetchRootKey().catch(err=>{
console.warn("Unable to fetch root key. Check to ensure that your local replica is running");
console.error(err);
});
}

// Creates an actor with using the candid interface and the HttpAgent
return Actor.createActor(idlFactory, {
agent,
canisterId,
...options?.actorOptions,
});
};

/**
* A ready-to-use agent for the storage canister
* @type {import("@dfinity/agent").ActorSubclass<import("./storage.did.js")._SERVICE>}
*/
export const storage = createActor(canisterId);
47 changes: 47 additions & 0 deletions .dfx/local/canisters/storage/storage.did
@@ -0,0 +1,47 @@
type Timestamp = int;
type FileUploadResult =
record {
bucketId: principal;
fileId: FileId;
};
type FileInfo =
record {
chunkCount: nat;
contentDisposition: text;
createdAt: Timestamp;
filetype: text;
name: text;
size: nat;
};
type FileId__1 = text;
type FileId = text;
type FileData =
record {
chunkCount: nat;
cid: principal;
contentDisposition: text;
createdAt: Timestamp;
fileId: FileId;
filetype: text;
name: text;
size: nat;
uploadedAt: Timestamp;
};
type Container =
service {
delFileChunk: (FileId__1, nat, principal) -> (opt null);
delFileInfo: (FileId__1, principal) -> (opt null);
getAllFiles: () -> (vec FileData);
getFileChunk: (FileId__1, nat, principal) -> (opt blob);
getFileInfo: (FileId__1, principal) -> (opt FileData);
getStatus: () -> (vec record {
principal;
nat;
}) query;
putFileChunk: (FileId__1, nat, blob) -> (principal);
putFileInfo: (FileInfo) -> (opt FileUploadResult);
updateStatus: () -> ();
wallet_balance: () -> (nat);
wallet_receive: () -> ();
};
service : () -> Container
52 changes: 52 additions & 0 deletions .dfx/local/canisters/storage/storage.did.d.ts
@@ -0,0 +1,52 @@
import type { Principal } from '@dfinity/principal';
export interface Container {
'delFileChunk' : (
arg_0: FileId__1,
arg_1: bigint,
arg_2: Principal,
) => Promise<[] | [null]>,
'delFileInfo' : (arg_0: FileId__1, arg_1: Principal) => Promise<[] | [null]>,
'getAllFiles' : () => Promise<Array<FileData>>,
'getFileChunk' : (
arg_0: FileId__1,
arg_1: bigint,
arg_2: Principal,
) => Promise<[] | [Array<number>]>,
'getFileInfo' : (arg_0: FileId__1, arg_1: Principal) => Promise<
[] | [FileData]
>,
'getStatus' : () => Promise<Array<[Principal, bigint]>>,
'putFileChunk' : (
arg_0: FileId__1,
arg_1: bigint,
arg_2: Array<number>,
) => Promise<Principal>,
'putFileInfo' : (arg_0: FileInfo) => Promise<[] | [FileUploadResult]>,
'updateStatus' : () => Promise<undefined>,
'wallet_balance' : () => Promise<bigint>,
'wallet_receive' : () => Promise<undefined>,
}
export interface FileData {
'cid' : Principal,
'contentDisposition' : string,
'name' : string,
'createdAt' : Timestamp,
'size' : bigint,
'filetype' : string,
'fileId' : FileId,
'chunkCount' : bigint,
'uploadedAt' : Timestamp,
}
export type FileId = string;
export type FileId__1 = string;
export interface FileInfo {
'contentDisposition' : string,
'name' : string,
'createdAt' : Timestamp,
'size' : bigint,
'filetype' : string,
'chunkCount' : bigint,
}
export interface FileUploadResult { 'bucketId' : Principal, 'fileId' : FileId }
export type Timestamp = bigint;
export interface _SERVICE extends Container {}
67 changes: 67 additions & 0 deletions .dfx/local/canisters/storage/storage.did.js
@@ -0,0 +1,67 @@
export const idlFactory = ({ IDL }) => {
const FileId__1 = IDL.Text;
const Timestamp = IDL.Int;
const FileId = IDL.Text;
const FileData = IDL.Record({
'cid' : IDL.Principal,
'contentDisposition' : IDL.Text,
'name' : IDL.Text,
'createdAt' : Timestamp,
'size' : IDL.Nat,
'filetype' : IDL.Text,
'fileId' : FileId,
'chunkCount' : IDL.Nat,
'uploadedAt' : Timestamp,
});
const FileInfo = IDL.Record({
'contentDisposition' : IDL.Text,
'name' : IDL.Text,
'createdAt' : Timestamp,
'size' : IDL.Nat,
'filetype' : IDL.Text,
'chunkCount' : IDL.Nat,
});
const FileUploadResult = IDL.Record({
'bucketId' : IDL.Principal,
'fileId' : FileId,
});
const Container = IDL.Service({
'delFileChunk' : IDL.Func(
[FileId__1, IDL.Nat, IDL.Principal],
[IDL.Opt(IDL.Null)],
[],
),
'delFileInfo' : IDL.Func(
[FileId__1, IDL.Principal],
[IDL.Opt(IDL.Null)],
[],
),
'getAllFiles' : IDL.Func([], [IDL.Vec(FileData)], []),
'getFileChunk' : IDL.Func(
[FileId__1, IDL.Nat, IDL.Principal],
[IDL.Opt(IDL.Vec(IDL.Nat8))],
[],
),
'getFileInfo' : IDL.Func(
[FileId__1, IDL.Principal],
[IDL.Opt(FileData)],
[],
),
'getStatus' : IDL.Func(
[],
[IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Nat))],
['query'],
),
'putFileChunk' : IDL.Func(
[FileId__1, IDL.Nat, IDL.Vec(IDL.Nat8)],
[IDL.Principal],
[],
),
'putFileInfo' : IDL.Func([FileInfo], [IDL.Opt(FileUploadResult)], []),
'updateStatus' : IDL.Func([], [], []),
'wallet_balance' : IDL.Func([], [IDL.Nat], []),
'wallet_receive' : IDL.Func([], [], []),
});
return Container;
};
export const init = ({ IDL }) => { return []; };
Binary file added .dfx/local/canisters/storage/storage.wasm
Binary file not shown.
7 changes: 7 additions & 0 deletions .dfx/local/wallets.json
@@ -0,0 +1,7 @@
{
"identities": {
"default": {
"local": "q4eej-kyaaa-aaaaa-aaaha-cai"
}
}
}
16 changes: 16 additions & 0 deletions dfx.json
@@ -0,0 +1,16 @@
{
"canisters": {
"storage": {
"main": "src/storage/Container.mo",
"type": "motoko"
}
},
"dfx": "0.8.3",
"networks": {
"local": {
"bind": "127.0.0.1:8000",
"type": "ephemeral"
}
},
"version": 1
}

1 comment on commit 46fe3ad

@blockchainstar1112
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. Great. I work video streaming now. Could you please help me?

Please sign in to comment.