Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ const handler = async function(argv) {
const filesAddress = deriveAddress(filesSeed, 0)

// Initialize endpoint connection
const endpoint = argv.endpoint
// when given endpoint ends with "/" http://192.168.1.8:4000/ results in irregular links
// bad link=> http://192.168.1.8:4000//api/web_hosting/address/
// bad link=> http://192.168.1.8:4000//explorer/transaction/000
const endpoint = new URL(argv.endpoint).origin

console.log(`Connecting to ${endpoint}`)

Expand Down
11 changes: 7 additions & 4 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ export default class AEWeb {

addFile(naivePath, data) {
const size = Buffer.byteLength(data)
if (size === 0) return

const hash = nativeCryptoLib.createHash(HASH_FUNCTION).update(data).digest('hex')
const content = zlib.gzipSync(data).toString('base64url')

const tabPath = naivePath.split(path.sep)
if (tabPath[0] === '') tabPath.shift()
const filePath = tabPath.join('/')

this.metaData[filePath] = {hash: hash, size: size, encoding: 'gzip', addresses: []}
this.metaData[filePath] = { hash: hash, size: size, encoding: 'gzip', addresses: [] }

// Handle file over than Max size. The file is splitted in multiple transactions,
// firsts parts take a full transaction, the last part follow the normal sized file construction
Expand Down Expand Up @@ -63,7 +65,7 @@ export default class AEWeb {
}

async getRefTransaction(transactions) {
const {metaData, refContent} = getMetaData(this.txsContent, transactions, this.metaData, this.sslCertificate)
const { metaData, refContent } = getMetaData(this.txsContent, transactions, this.metaData, this.sslCertificate)
this.metaData = metaData

const refTx = this.archethic.transaction.new()
Expand Down Expand Up @@ -108,7 +110,8 @@ function handleBigFile(txsContent, filePath, content) {
}

function handleNormalFile(txsContent, filePath, content) {
const fileSize = content.length
// 4 x "inverted commas + 1x :Colon + 1x ,Comma + 1x space = 7
const fileSize = content.length + filePath.length + 7
// Get first transaction content that can be filled with file content
const txContent = getContentToFill(txsContent, fileSize)
const index = txsContent.indexOf(txContent)
Expand Down Expand Up @@ -169,7 +172,7 @@ function getMetaData(txsContent, transactions, metaData, sslCertificate) {
ref.sslCertificate = sslCertificate
}

return {metadata: metaData, refContent: JSON.stringify((ref))}
return { metadata: metaData, refContent: JSON.stringify((ref)) }
}

function sortObject(obj) {
Expand Down
105 changes: 54 additions & 51 deletions package-lock.json

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