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
1 change: 1 addition & 0 deletions src/@types/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface DownloadCommand extends Command {
signature: string
aes_encrypted_key?: string // if not present it means download without encryption
policyServer?: PolicyServerTask // object to pass to policy server
userData?: Record<string, any>
}

export interface FileInfoCommand extends Command {
Expand Down
12 changes: 12 additions & 0 deletions src/components/core/handler/downloadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,18 @@ export class DownloadHandler extends CommandHandler {
decriptedFileObject = decryptedFileData.files[task.fileIndex]
}

CORE_LOGGER.info('Decrypted file object: ' + JSON.stringify(decriptedFileObject))
if (decriptedFileObject?.url && task.userData) {
const url = new URL(decriptedFileObject.url)
const userDataObj =
typeof task.userData === 'string' ? JSON.parse(task.userData) : task.userData
for (const [key, value] of Object.entries(userDataObj)) {
url.searchParams.append(key, String(value))
}
decriptedFileObject.url = url.toString()
CORE_LOGGER.info('Appended userData to file url: ' + decriptedFileObject.url)
}

if (!validateFilesStructure(ddo, service, decryptedFileData)) {
CORE_LOGGER.error(
'Unauthorized download operation. Decrypted "nftAddress" and "datatokenAddress" do not match the original DDO'
Expand Down
17 changes: 15 additions & 2 deletions src/components/httpRoutes/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,21 @@ providerRoutes.get(
transferTxId,
nonce,
consumerAddress,
signature
signature,
userdata
} = req.query

let parsedUserData: any = null
if (userdata) {
try {
parsedUserData = JSON.parse(userdata as string)
} catch (e) {
// Log error but don't block request if userdata is malformed
HTTP_LOGGER.logMessage(`Invalid userdata JSON: ${userdata}`, true)
parsedUserData = null
}
}

const downloadTask: DownloadCommand = {
fileIndex: Number(fileIndex),
documentId: documentId as string,
Expand All @@ -222,7 +234,8 @@ providerRoutes.get(
signature: signature as string,
command: PROTOCOL_COMMANDS.DOWNLOAD,
policyServer: (req.query.policyServer as any) || null,
authorization: authorization as string
authorization: authorization as string,
userData: parsedUserData
}

const response = await new DownloadHandler(req.oceanNode).handle(downloadTask)
Expand Down
Loading