Skip to content
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ PORT=3456 # Daemon port
DATABASE_PATH=./pins.db # SQLite database
CAR_STORAGE_PATH=./cars # CAR file directory
LOG_LEVEL=info # Logging level
WITH_CDN=true # Enable/Disable CDN for content uploads (default: false)
```

### Default Directories
Expand Down Expand Up @@ -193,4 +194,4 @@ Dual-licensed under [MIT](LICENSE-MIT) + [Apache 2.0](LICENSE-APACHE)

- [IPFS Pinning Service API](https://ipfs.github.io/pinning-services-api-spec/)
- [Synapse SDK](https://github.com/filecoin-project/synapse-sdk)
- [USDFC Documentation](https://docs.secured.finance/usdfc-stablecoin)
- [USDFC Documentation](https://docs.secured.finance/usdfc-stablecoin)
13 changes: 13 additions & 0 deletions src/add/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { readFile, stat } from 'node:fs/promises'
import { RPC_URLS } from '@filoz/synapse-sdk'
import pc from 'picocolors'
import pino from 'pino'
import { warnAboutCDNPricingLimitations } from '../common/cdn-warning.js'
import { envToBool } from '../common/env-vars.js'
import { displayUploadResults, performUpload, validatePaymentSetup } from '../common/upload-flow.js'
import {
cleanupSynapseService,
Expand Down Expand Up @@ -71,6 +73,17 @@ export async function runAdd(options: AddOptions): Promise<AddResult> {
level: process.env.LOG_LEVEL || 'error',
})

// Check CDN status and warn if enabled
const withCDN = envToBool(process.env.WITH_CDN, false)
if (withCDN) {
const proceed = await warnAboutCDNPricingLimitations()
if (!proceed) {
cancel('Add cancelled')
process.exitCode = 1
throw new Error('CDN pricing limitations warning cancelled')
}
}

let tempCarPath: string | undefined

try {
Expand Down
28 changes: 28 additions & 0 deletions src/common/cdn-warning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { cancel, confirm } from '@clack/prompts'
import pc from 'picocolors'
import { log } from '../utils/cli-logger.js'

export async function warnAboutCDNPricingLimitations(): Promise<boolean> {
log.warn(pc.red('CDN Pricing Notice'))
log.newline()
log.line('Filecoin-pin currently does not support CDN pricing in payment calculations.')
log.newline()
log.line('This means:')
log.indent('• Deposit calculations may not be accurate for CDN storage')
log.indent('• You may need additional USDFC deposits for CDN-enabled uploads')
log.indent('• Filcdn is transitioning to egress-based billing (from fixed fees)')
log.newline()
log.flush()

const shouldProceed = await confirm({
message: 'Do you want to proceed with CDN-enabled upload?',
initialValue: false,
})

if (shouldProceed === null) {
cancel('Operation cancelled')
process.exitCode = 1
}

return Boolean(shouldProceed)
}
11 changes: 11 additions & 0 deletions src/common/env-vars.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Generic helpers for environment variable parsing and validation.
*/

export const envToBool = (value: string | undefined, defaultValue: boolean): boolean => {
if (value === undefined) return defaultValue
const normalized = value.trim().toLowerCase()
if (['1', 'true', 'yes', 'on'].includes(normalized)) return true
if (['0', 'false', 'no', 'off'].includes(normalized)) return false
return defaultValue
}
13 changes: 13 additions & 0 deletions src/import/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { CarReader } from '@ipld/car'
import { CID } from 'multiformats/cid'
import pc from 'picocolors'
import pino from 'pino'
import { warnAboutCDNPricingLimitations } from '../common/cdn-warning.js'
import { envToBool } from '../common/env-vars.js'
import { displayUploadResults, performUpload, validatePaymentSetup } from '../common/upload-flow.js'
import {
cleanupSynapseService,
Expand Down Expand Up @@ -130,6 +132,17 @@ export async function runCarImport(options: ImportOptions): Promise<ImportResult
level: process.env.LOG_LEVEL || 'error',
})

// Check CDN status and warn if enabled
const withCDN = envToBool(process.env.WITH_CDN, false)
if (withCDN) {
const proceed = await warnAboutCDNPricingLimitations()
if (!proceed) {
cancel('Import cancelled')
process.exitCode = 1
throw new Error('CDN pricing limitations warning cancelled')
}
}

try {
// Step 1: Validate file exists and is readable
spinner.start('Validating CAR file...')
Expand Down
3 changes: 2 additions & 1 deletion src/synapse/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type SynapseOptions,
} from '@filoz/synapse-sdk'
import type { Logger } from 'pino'
import { envToBool } from '../common/env-vars.js'
import type { Config } from '../config.js'

/**
Expand All @@ -22,7 +23,7 @@ const DEFAULT_DATA_SET_METADATA = {
* Default configuration for creating storage contexts
*/
const DEFAULT_STORAGE_CONTEXT_CONFIG = {
withCDN: false, // CDN not needed for Filecoin Pin currently
withCDN: envToBool(process.env.WITH_CDN, false),
metadata: DEFAULT_DATA_SET_METADATA,
} as const

Expand Down