Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Provider.checkFileUrl to allow non-URL file types (like Arweave) #1627

Merged
merged 15 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/services/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Web3 from 'web3'
import fetch from 'cross-fetch'
import { LoggerInstance } from '../utils'
import {
Arweave,
FileInfo,
ComputeJob,
ComputeOutput,
Expand All @@ -11,6 +12,7 @@ import {
ProviderInitialize,
ProviderComputeInitializeResults,
ServiceEndpoint,
UrlFile,
UserCustomParameters
} from '../@types'

Expand Down Expand Up @@ -193,8 +195,8 @@ export class Provider {
* @param {AbortSignal} signal abort signal
* @return {Promise<FileInfo[]>} urlDetails
*/
public async checkFileUrl(
url: string,
public async getFileInfo(
file: UrlFile | Arweave,
kremalicious marked this conversation as resolved.
Show resolved Hide resolved
providerUri: string,
signal?: AbortSignal
): Promise<FileInfo[]> {
Expand All @@ -203,7 +205,7 @@ export class Provider {
providerUri,
providerEndpoints
)
const args = { url, type: 'url' }
const args = file
const files: FileInfo[] = []
const path = this.getEndpointURL(serviceEndpoints, 'fileinfo')
? this.getEndpointURL(serviceEndpoints, 'fileinfo').urlPath
Expand Down
21 changes: 18 additions & 3 deletions test/integration/Provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,24 @@ describe('Provider tests', async () => {
assert(valid === true)
})

it('Alice checks fileinfo', async () => {
const fileinfo: FileInfo[] = await providerInstance.checkFileUrl(
'https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-abstract.xml.gz-rss.xml',
it('Alice checks URL fileinfo', async () => {
const fileinfo: FileInfo[] = await providerInstance.getFileInfo(
{
type: 'url',
url: 'https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-abstract.xml.gz-rss.xml',
method: 'GET'
},
config.providerUri
)
assert(fileinfo[0].valid === true, 'Sent file is not valid')
})

it('Alice checks Arweave fileinfo', async () => {
const fileinfo: FileInfo[] = await providerInstance.getFileInfo(
{
type: 'arweave',
transactionId: 'a4qJoQZa1poIv5guEzkfgZYSAD0uYm7Vw4zm_tCswVQ',
kremalicious marked this conversation as resolved.
Show resolved Hide resolved
},
config.providerUri
)
assert(fileinfo[0].valid === true, 'Sent file is not valid')
Expand Down