Skip to content

Commit 9f1bda1

Browse files
authored
Merge pull request #1693 from demergent-labs/stable-infinite-files
Stable infinite files
2 parents 0f3484e + 8367faa commit 9f1bda1

File tree

165 files changed

+6479
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+6479
-207
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ jobs:
112112
"examples/inspect_message",
113113
"examples/internet_identity",
114114
"examples/key_value_store",
115+
"examples/large_files",
115116
"examples/ledger_canister",
116117
"examples/list_of_lists",
117118
"examples/management_canister",

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dfx/index.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { execSync } from 'child_process';
2+
import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
3+
import { readFile } from 'fs/promises';
4+
import { homedir } from 'os';
5+
import { join } from 'path';
6+
import { HttpAgent } from '@dfinity/agent';
7+
8+
export function getCanisterId(canisterName: string): string {
9+
return execSync(
10+
`dfx canister --network ${
11+
process.env.DFX_NETWORK ?? 'local'
12+
} id ${canisterName}`
13+
)
14+
.toString()
15+
.trim();
16+
}
17+
18+
export function getWebServerPort(): string {
19+
return execSync(`dfx info webserver-port`).toString().trim();
20+
}
21+
22+
export function getCanisterOrigin(canisterName: string): string {
23+
return `http://${getCanisterId(
24+
canisterName
25+
)}.localhost:${getWebServerPort()}`;
26+
}
27+
28+
export function getAgentHost(): string {
29+
return process.env.DFX_NETWORK === 'ic'
30+
? `https://icp-api.io`
31+
: `http://127.0.0.1:${getWebServerPort()}`;
32+
}
33+
34+
export async function createAnonymousAgent() {
35+
const agent = new HttpAgent({
36+
host: getAgentHost()
37+
});
38+
39+
if (process.env.DFX_NETWORK !== 'ic') {
40+
await agent.fetchRootKey();
41+
}
42+
}
43+
44+
export async function createAuthenticatedAgent(
45+
identityName?: string
46+
): Promise<HttpAgent> {
47+
const agent = new HttpAgent({
48+
host: getAgentHost(),
49+
identity: getIdentity(identityName)
50+
});
51+
52+
if (process.env.DFX_NETWORK !== 'ic') {
53+
await agent.fetchRootKey();
54+
}
55+
56+
return agent;
57+
}
58+
59+
export function getIdentityName(): string {
60+
return execSync(`dfx identity whoami`).toString().trim();
61+
}
62+
63+
export function generateIdentity(name: string) {
64+
execSync(`dfx identity new ${name} --storage-mode plaintext`);
65+
}
66+
67+
export function useIdentity(name: string) {
68+
execSync(`dfx identity use ${name}`);
69+
}
70+
71+
export function getIdentities(): string[] {
72+
const list = execSync(`dfx identity list`).toString().trim();
73+
const identities = list.split('\n');
74+
75+
return identities;
76+
}
77+
78+
export function removeIdentity(name: string) {
79+
execSync(`dfx identity remove ${name}`);
80+
}
81+
82+
export async function getIdentity(
83+
identityName: string = getIdentityName()
84+
): Promise<Secp256k1KeyIdentity> {
85+
const identityPath = join(
86+
homedir(),
87+
'.config',
88+
'dfx',
89+
'identity',
90+
identityName,
91+
'identity.pem'
92+
);
93+
return Secp256k1KeyIdentity.fromPem(await readFile(identityPath, 'utf-8'));
94+
}

examples/apollo_server/test/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getCanisterId, runTests } from 'azle/test';
1+
import { getCanisterId } from 'azle/dfx';
2+
import { runTests } from 'azle/test';
23
import { getTests } from './tests';
34

45
const canisterId = getCanisterId('apollo_server');

examples/async_await/test/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getCanisterId, runTests } from 'azle/test';
1+
import { getCanisterId } from 'azle/dfx';
2+
import { runTests } from 'azle/test';
23
import { createActor } from './dfx_generated/async_await';
34
import { get_tests } from './tests';
45

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.azle
22
.dfx
33
node_modules
4+
src/backend/media/jordan_video_streaming_demo.mp4
5+
src/backend/media/popeye_the_sailor_meets_sindbad_the_sailor.mp4
6+
src/backend/media/the_memphis_belle.mp4

examples/audio_and_video/dfx.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@
1010
"gzip": true,
1111
"assets": [
1212
["src/frontend/dist", "dist"],
13-
["src/backend/media", "media"]
13+
["src/backend/media/audio.ogg", "media/audio.ogg"],
14+
["src/backend/media/video.ogv", "media/video.ogv"]
1415
],
16+
"assets_large_commented_out": [
17+
[
18+
"src/backend/media/jordan_video_streaming_demo.mp4",
19+
"media/jordan_video_streaming_demo.mp4"
20+
],
21+
[
22+
"src/backend/media/popeye_the_sailor_meets_sindbad_the_sailor.mp4",
23+
"media/popeye_the_sailor_meets_sindbad_the_sailor.mp4"
24+
]
25+
],
26+
"post_install": "npx azle upload-assets backend",
1527
"build_assets": "npm run build",
1628
"metadata": [
1729
{

examples/audio_and_video/src/frontend/index.html

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,95 @@
22

33
<html>
44
<head>
5-
<title>Audio and Video</title>
5+
<title>ICP Video/Audio Streaming w/ Range Requests</title>
66
</head>
77

88
<body>
9-
<video
10-
src="media/video.ogv"
11-
controls
12-
></video>
13-
<audio
14-
src="media/audio.ogg"
15-
controls
16-
></audio>
9+
<style>
10+
.title {
11+
display: flex;
12+
flex-direction: column;
13+
align-items: center;
14+
}
15+
16+
.info {
17+
padding-bottom: 25px;
18+
}
19+
20+
.media-container {
21+
display: flex;
22+
flex-direction: column;
23+
justify-content: center;
24+
align-items: center;
25+
}
26+
27+
.media-title {
28+
padding: 25px;
29+
}
30+
31+
video {
32+
max-height: 75vh;
33+
}
34+
</style>
35+
36+
<div class="title">
37+
<h1>ICP Video/Audio Streaming w/ Range Requests</h1>
38+
<div class="info">
39+
<div>
40+
1.
41+
<a
42+
href="https://github.com/demergent-labs/azle/blob/main/examples/audio_and_video/src/backend/server.ts"
43+
target="_blank"
44+
>View the incredibly simple source code</a
45+
>
46+
</div>
47+
<div>
48+
2. Details on scalability are not fully known yet (consider
49+
boundary node caching/limits + subnet/canister query limits)
50+
</div>
51+
<div>
52+
3. Streaming is currently free (besides storage, upload,
53+
etc); this will most likely change in the future
54+
</div>
55+
<div>
56+
4. Very large file uploads (greater than ~20 MiB) will be
57+
released in subsequent versions of Azle
58+
</div>
59+
</div>
60+
</div>
61+
62+
<div class="media-container">
63+
<video
64+
src="media/jordan_video_streaming_demo.mp4"
65+
controls
66+
></video>
67+
<div class="media-title">
68+
Jordan Video Streaming Demo - 17.78 MiB
69+
</div>
70+
</div>
71+
72+
<div class="media-container">
73+
<video
74+
src="media/popeye_the_sailor_meets_sindbad_the_sailor.mp4"
75+
controls
76+
></video>
77+
<div class="media-title">
78+
<a
79+
href="https://www.loc.gov/item/mbrs00068306"
80+
target="_blank"
81+
>Popeye the Sailor Meets Sindbad the Sailor - 611.98 MiB</a
82+
>
83+
</div>
84+
</div>
85+
86+
<div class="media-container">
87+
<audio
88+
src="media/audio.ogg"
89+
controls
90+
></audio>
91+
<div class="media-title">
92+
Abraham Lincoln's Second Inaugural Address - 5.33 MiB
93+
</div>
94+
</div>
1795
</body>
1896
</html>

examples/audio_and_video/test/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getCanisterId, runTests } from 'azle/test';
1+
import { getCanisterId } from 'azle/dfx';
2+
import { runTests } from 'azle/test';
23
import { getTests } from './tests';
34

45
const canisterId = getCanisterId('backend');

examples/audio_recorder/test/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getCanisterId, runTests } from 'azle/test';
1+
import { getCanisterId } from 'azle/dfx';
2+
import { runTests } from 'azle/test';
23
import { createActor } from '../test/dfx_generated/audio_recorder';
34
import { get_tests } from './tests';
45

0 commit comments

Comments
 (0)