Skip to content

Commit

Permalink
CID type selection improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Jan 16, 2025
1 parent 4226b75 commit 405d425
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

10 changes: 7 additions & 3 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import { path } from './deps.ts'
import { upload } from './upload.ts'

// Prefixes to use to select the correct CID to use
const CONTRACT_TEXT_PREFIX = `t|`
const CONTRACT_MANIFEST_PREFIX = `m|`

export async function deploy (args: string[]) {
const [urlOrDirOrSqliteFile, ...manifests] = args
if (manifests.length === 0) throw new Error('missing url or manifests!')
Expand All @@ -13,11 +17,11 @@ export async function deploy (args: string[]) {
const json = JSON.parse(Deno.readTextFileSync(manifestPath))
const body = JSON.parse(json.body)
const dirname = path.dirname(manifestPath)
toUpload.push('t|' + path.join(dirname, body.contract.file))
toUpload.push(CONTRACT_TEXT_PREFIX + path.join(dirname, body.contract.file))
if (body.contractSlim) {
toUpload.push('t|' + path.join(dirname, body.contractSlim.file))
toUpload.push(CONTRACT_TEXT_PREFIX + path.join(dirname, body.contractSlim.file))
}
toUpload.push('m|' + manifestPath)
toUpload.push(CONTRACT_MANIFEST_PREFIX + manifestPath)
}
await upload([urlOrDirOrSqliteFile, ...toUpload], true)
}
4 changes: 3 additions & 1 deletion src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export async function upload (args: string[], internal = false) {
for (const filepath_ of files) {
let type = multicodes.RAW
let filepath = filepath_
if (filepath_[1] === '|') {
if (internal) {
// The `{type}|` prefix is used to determine which kind of CID is needed
if (filepath_[1] !== '|') throw new Error('Invalid path format')
switch (filepath_[0]) {
case 'r':
// raw file type
Expand Down

0 comments on commit 405d425

Please sign in to comment.