Skip to content

Commit

Permalink
chore: remove legacy upload codepath
Browse files Browse the repository at this point in the history
plus feature flag and related tests
  • Loading branch information
travis committed Apr 12, 2024
1 parent 69af59d commit cb4b333
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 341 deletions.
8 changes: 0 additions & 8 deletions decisions/20240313-try-w3up.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ configures how nft.storage will authenticate to web3.storage when sending invoca
configures the capabilities that nft.storage has access to when interacting with web3.storage to store nfts. These capabilities will usually be UCAN delegations whose audience is the identifier of `W3_NFTSTORAGE_PRINCIPAL`.
W3_NFTSTORAGE_PROOF needs to have proof rooted in W3_NFTSTORAGE_SPACE that authorize W3_NFTSTORAGE_PRINCIPAL to store in W3_NFTSTORAGE_SPACE.

##### `W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS` Environment Variable

configures feature switch for which nftstorage accounts will have new uploads stored in web3.storage.

Note: this environment variable may not be a permanent addition to the codebase. It's only meant to be used as a feature switch that decouples enabling the new functionality from deploying the new code. After testing, we may remove or change this feature switch when it is no longer useful.

Format: JSON Array of email address strings.

#### UI Changes

None. But the existing UI workflow of uploading via https://nft.storage/files/ and form should behave just like they do now. But after this change, there should be a new side effect, which is that the upload should appear in the listing of uploads for the configured `W3_NFTSTORAGE_SPACE` (e.g. via w3cli `w3 ls` or in console.web3.storage).
Expand Down
8 changes: 0 additions & 8 deletions packages/api/src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ export interface ServiceConfiguration {

/** did:key of the w3up space in which to store NFTs */
W3_NFTSTORAGE_SPACE?: string

/**
* JSON array of strings that are emails whose uploads should be uploaded via w3up.
* This is meant as a feature switch to test new functionality,
* and this configuration may be removed once the feature switch isn't needed to limit access.
*/
W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS?: string
}

export interface Ucan {
Expand Down Expand Up @@ -161,7 +154,6 @@ export interface RouteContext {
W3_NFTSTORAGE_PRINCIPAL?: string
W3_NFTSTORAGE_PROOF?: string
W3_NFTSTORAGE_SPACE?: string
W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS?: string
w3up?: W3upClient
contentClaims?: ContentClaimsClient
}
Expand Down
3 changes: 0 additions & 3 deletions packages/api/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ export function serviceConfigFromVariables(vars) {
W3_NFTSTORAGE_PRINCIPAL: vars.W3_NFTSTORAGE_PRINCIPAL,
W3_NFTSTORAGE_PROOF: vars.W3_NFTSTORAGE_PROOF,
W3_NFTSTORAGE_SPACE: vars.W3_NFTSTORAGE_SPACE,
W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS:
vars.W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS,
}
}

Expand Down Expand Up @@ -136,7 +134,6 @@ export function loadConfigVariables() {
'W3_NFTSTORAGE_SPACE',
'W3_NFTSTORAGE_PRINCIPAL',
'W3_NFTSTORAGE_PROOF',
'W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS',
]

for (const name of optional) {
Expand Down
51 changes: 3 additions & 48 deletions packages/api/src/routes/nfts-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,6 @@ export async function nftUpload(event, ctx) {
return new JSONResponse({ ok: true, value: toNFTResponse(upload) })
}

/**
* returns whether w3up uploading feature is enabled given context + event
* @param {object} context - context of server operation, e.g. including configuration of feature switch
* @param {string} [context.W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS] - JSON array of allowed emails
* @param {object} event - specific event for which we should determine whether w3up feature is enabled
* @param {object} event.user
* @param {string} event.user.email - email address of user associated with event
*/
function w3upFeatureSwitchEnabled(context, event) {
// const { W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS = '[]' } = context
// const allowedEmails = JSON.parse(W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS)
// if (!Array.isArray(allowedEmails)) return false
// const eventHasAllowedEmail = allowedEmails.find(
// (allowed) => allowed === event.user.email
// )
return true
}

/**
* @typedef {{
* event: FetchEvent,
Expand Down Expand Up @@ -170,10 +152,8 @@ export async function uploadCarWithStat(
/** @type {(() => Promise<void>)|undefined} */
let checkDagStructureTask
const backupUrls = []
// @ts-expect-error email is not expected in types
if (ctx.w3up && w3upFeatureSwitchEnabled(ctx, { user })) {
const { w3up } = ctx

const { w3up } = ctx
if (w3up) {
// we perform store/add and upload/add concurrently to save time.
await Promise.all([
w3up.capability.store.add(car),
Expand Down Expand Up @@ -204,32 +184,7 @@ export async function uploadCarWithStat(
}
}
} else {
const carBytes = new Uint8Array(await car.arrayBuffer())
const [s3Backup, r2Backup] = await Promise.all([
ctx.s3Uploader.uploadCar(carBytes, stat.cid, user.id, metadata),
ctx.r2Uploader.uploadCar(carBytes, stat.cid, user.id, metadata),
])
backupUrls.push(s3Backup.url, r2Backup.url)

// no need to ask linkdex if it's Complete or Unknown
if (stat.structure === 'Partial') {
// ask linkdex for the dag structure across the set of CARs in S3 for this upload.
checkDagStructureTask = async () => {
try {
const structure = await ctx.linkdexApi.getDagStructure(s3Backup.key)
if (structure === 'Complete') {
return ctx.db.updatePinStatus(
upload.content_cid,
elasticPin(structure)
)
}
} catch (/** @type {any} */ err) {
if (err.code !== MissingApiUrlCode) {
throw err
}
}
}
}
throw new Error('w3up not defined, cannot upload')
}
const xName = event.request.headers.get('x-name')
let name = xName && decodeURIComponent(xName)
Expand Down
2 changes: 0 additions & 2 deletions packages/api/src/utils/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export async function getContext(event, params) {
W3_NFTSTORAGE_PRINCIPAL: config.W3_NFTSTORAGE_PRINCIPAL,
W3_NFTSTORAGE_PROOF: config.W3_NFTSTORAGE_PROOF,
W3_NFTSTORAGE_SPACE: config.W3_NFTSTORAGE_SPACE,
W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS:
config.W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS,
}
let w3up
if (
Expand Down
3 changes: 0 additions & 3 deletions packages/api/test/nfts-get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ test.before(async (t) => {
})
)
).toString(base64),
W3_NFTSTORAGE_ENABLE_W3UP_FOR_EMAILS: JSON.stringify([
nftStorageAccountEmailAllowListedForW3up,
]),
},
})
})
Expand Down
Loading

0 comments on commit cb4b333

Please sign in to comment.