Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
upalinski committed Nov 7, 2024
1 parent 289ab2b commit 6e4363b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"encoded":"kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf","encoding":{"content":["pkcs8","ed25519"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"address":"5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP","meta":{}}
{
"encoded": "kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf",
"encoding": { "content": ["pkcs8", "ed25519"], "type": ["scrypt", "xsalsa20-poly1305"], "version": "3" },
"address": "5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP",
"meta": {}
}
18 changes: 8 additions & 10 deletions examples/node/5-use-exported-account/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {
DdcClient,
File,
TESTNET,
JsonSigner,
} from '@cere-ddc-sdk/ddc-client';
import { DdcClient, File, TESTNET, JsonSigner } from '@cere-ddc-sdk/ddc-client';
import * as fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
import { fileURLToPath } from 'url';

// The wallet should have enough CERE to pay for the transaction fees
const pathToAccount = './6S5nrcLgUrhC2tLpaG83VLrMndnQ66DPTz7j6PoRnQjZKpvx.json';
Expand All @@ -20,14 +15,17 @@ const dir = path.dirname(fileURLToPath(import.meta.url));

// Create DDC client instance using JSON account exported from Cere Wallet
const keyringPair = JSON.parse(fs.readFileSync(path.resolve(dir, pathToAccount)).toString());
const jsonSigner = new JsonSigner(keyringPair, {passphrase: accountPassphrase});
const jsonSigner = new JsonSigner(keyringPair, { passphrase: accountPassphrase });
const client = await DdcClient.create(jsonSigner, TESTNET);

// Upload file
const pathToFileToUpload = path.resolve(dir, '../assets/nature.jpg');
const fileToUpload = new File(fs.createReadStream(pathToFileToUpload), {size: fs.statSync(pathToFileToUpload).size});
const fileToUpload = new File(fs.createReadStream(pathToFileToUpload), { size: fs.statSync(pathToFileToUpload).size });
const uploadedFileUri = await client.store(bucketId, fileToUpload);
console.log('The file can be accessed by this URL', `https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`);
console.log(
'The file can be accessed by this URL',
`https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`,
);
console.log('File stored into bucket', bucketId, 'with CID', uploadedFileUri.cid);

await client.disconnect();
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"encoded":"kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf","encoding":{"content":["pkcs8","ed25519"],"type":["scrypt","xsalsa20-poly1305"],"version":"3"},"address":"5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP","meta":{}}
{
"encoded": "kBkc/6ghJVs4thxE7ZMSRhxyVtYi2EzjJz8gvI2HfKQAgAAAAQAAAAgAAAAs5o9q7l+BpKkYsTXvuroLsxdysjikaK8qRkm13kzbnCfG5t9Df2QnQfHxrYyboPp5SoGdKxhnz5HRLK4/Fq1wPZpk43XSaa/b4PxOphxLfFYdjG2MJt80QSIzzRrP6TNj6R/YfMsKSySGqYHgiOkVnJJyZq0Exc35+3W6CyESzciXzDIw2iYzNdV5CJWpiAtgnW7tHxmsldKhUmYf",
"encoding": { "content": ["pkcs8", "ed25519"], "type": ["scrypt", "xsalsa20-poly1305"], "version": "3" },
"address": "5EdskhqqsNCUABVFhsZkxXfG2p4sRtf9ChU9iC5pE9bhx1kP",
"meta": {}
}
45 changes: 22 additions & 23 deletions examples/node/6-developer-console-compatibility/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
DdcClient,
File,
Link,
DagNodeUri,
DagNode,
JsonSigner,
TESTNET,
} from '@cere-ddc-sdk/ddc-client';
import { DdcClient, File, Link, DagNodeUri, DagNode, JsonSigner, TESTNET } from '@cere-ddc-sdk/ddc-client';
import * as fs from 'fs';
import {fileURLToPath} from 'url';
import { fileURLToPath } from 'url';
import path from 'path';

// The wallet should have enough CERE to pay for the transaction fees
Expand All @@ -26,8 +18,8 @@ const fileName = pathToFileToUpload.substring(pathToFileToUpload.lastIndexOf('/'

// Initialise client using JSON account exported from Cere Wallet
const keyringPair = JSON.parse(fs.readFileSync(path.resolve(dir, pathToAccount)).toString());
const jsonSigner = new JsonSigner(keyringPair, {passphrase: accountPassphrase});
const client = await DdcClient.create(jsonSigner, {...TESTNET, logLevel: 'fatal'});
const jsonSigner = new JsonSigner(keyringPair, { passphrase: accountPassphrase });
const client = await DdcClient.create(jsonSigner, { ...TESTNET, logLevel: 'fatal' });

// Upload file
const fileSize = fs.statSync(pathToFileToUpload).size;
Expand All @@ -36,20 +28,27 @@ const fileToUpload = new File(fs.createReadStream(pathToFileToUpload), {
});
const uploadedFileUri = await client.store(bucketId, fileToUpload);
console.log('File stored into bucket', bucketId, 'with CID', uploadedFileUri.cid);
console.log('The file can be accessed by this URL', `https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`);
console.log(
'The file can be accessed by this URL',
`https://cdn.testnet.cere.network/${bucketId}/${uploadedFileUri.cid}`,
);

// Attach uploaded file to 'fs' DAG node (where 'fs' is a CNS name used by Developer Console to index files)
const filePathInDeveloperConsole = 'photos/nature/';
const rootDagNode = await client.read(new DagNodeUri(bucketId, 'fs'), {cacheControl: 'no-cache'})
.catch((res) => {
if (res.message == 'Cannot resolve CNS name: "fs"') {
return new DagNode(null);
} else {
throw new Error('Failed to fetch \'fs\' DAG node');
}
});
const rootDagNode = await client.read(new DagNodeUri(bucketId, 'fs'), { cacheControl: 'no-cache' }).catch((res) => {
if (res.message == 'Cannot resolve CNS name: "fs"') {
return new DagNode(null);
} else {
throw new Error("Failed to fetch 'fs' DAG node");
}
});
rootDagNode.links.push(new Link(uploadedFileUri.cid, fileSize, filePathInDeveloperConsole + fileName));
await client.store(bucketId, rootDagNode, {name: 'fs'});
console.log('The file can be found in developer console in bucket', bucketId, 'and path is', filePathInDeveloperConsole);
await client.store(bucketId, rootDagNode, { name: 'fs' });
console.log(
'The file can be found in developer console in bucket',
bucketId,
'and path is',
filePathInDeveloperConsole,
);

await client.disconnect();

0 comments on commit 6e4363b

Please sign in to comment.