Skip to content

Commit 0a89ca8

Browse files
SgtPookirvagg
andauthored
feat: allow overriding withCDN via env-var (#55)
* feat: allow overriding withCDN via env-var * chore: fix lint * docs: indicate default value for WITH_CDN * fix: Warn users when enabling WITH_CDN * docs: update readme Co-authored-by: Rod Vagg <[email protected]> * chore: fix bad merge * chore: remove envToBool --------- Co-authored-by: Rod Vagg <[email protected]>
1 parent 5c204ed commit 0a89ca8

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/add/add.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { readFile, stat } from 'node:fs/promises'
99
import pc from 'picocolors'
1010
import pino from 'pino'
11+
import { warnAboutCDNPricingLimitations } from '../common/cdn-warning.js'
1112
import { displayUploadResults, performAutoFunding, performUpload, validatePaymentSetup } from '../common/upload-flow.js'
1213
import {
1314
cleanupSynapseService,
@@ -71,6 +72,17 @@ export async function runAdd(options: AddOptions): Promise<AddResult> {
7172
level: process.env.LOG_LEVEL || 'error',
7273
})
7374

75+
// Check CDN status and warn if enabled
76+
const withCDN = process.env.WITH_CDN === 'true'
77+
if (withCDN) {
78+
const proceed = await warnAboutCDNPricingLimitations()
79+
if (!proceed) {
80+
cancel('Add cancelled')
81+
process.exitCode = 1
82+
throw new Error('CDN pricing limitations warning cancelled')
83+
}
84+
}
85+
7486
let tempCarPath: string | undefined
7587

7688
try {

src/common/cdn-warning.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { cancel, confirm } from '@clack/prompts'
2+
import pc from 'picocolors'
3+
import { log } from '../utils/cli-logger.js'
4+
5+
export async function warnAboutCDNPricingLimitations(): Promise<boolean> {
6+
log.warn(pc.red('CDN Pricing Notice'))
7+
log.newline()
8+
log.line('Filecoin-pin currently does not support CDN pricing in payment calculations.')
9+
log.newline()
10+
log.line('This means:')
11+
log.indent('• Deposit calculations may not be accurate for CDN storage')
12+
log.indent('• You may need additional USDFC deposits for CDN-enabled uploads')
13+
log.indent('• Filcdn is transitioning to egress-based billing (from fixed fees)')
14+
log.newline()
15+
log.flush()
16+
17+
const shouldProceed = await confirm({
18+
message: 'Do you want to proceed with CDN-enabled upload?',
19+
initialValue: false,
20+
})
21+
22+
if (shouldProceed === null) {
23+
cancel('Operation cancelled')
24+
process.exitCode = 1
25+
}
26+
27+
return Boolean(shouldProceed)
28+
}

src/import/import.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { CarReader } from '@ipld/car'
1111
import { CID } from 'multiformats/cid'
1212
import pc from 'picocolors'
1313
import pino from 'pino'
14+
import { warnAboutCDNPricingLimitations } from '../common/cdn-warning.js'
1415
import { displayUploadResults, performAutoFunding, performUpload, validatePaymentSetup } from '../common/upload-flow.js'
1516
import {
1617
cleanupSynapseService,
@@ -130,6 +131,17 @@ export async function runCarImport(options: ImportOptions): Promise<ImportResult
130131
level: process.env.LOG_LEVEL || 'error',
131132
})
132133

134+
// Check CDN status and warn if enabled
135+
const withCDN = process.env.WITH_CDN === 'true'
136+
if (withCDN) {
137+
const proceed = await warnAboutCDNPricingLimitations()
138+
if (!proceed) {
139+
cancel('Import cancelled')
140+
process.exitCode = 1
141+
throw new Error('CDN pricing limitations warning cancelled')
142+
}
143+
}
144+
133145
try {
134146
// Step 1: Validate file exists and is readable
135147
spinner.start('Validating CAR file...')

0 commit comments

Comments
 (0)