forked from solana-labs/governance-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
read arweave link for proposal description (solana-labs#1797)
- Loading branch information
1 parent
c1a9602
commit 9cbf5b9
Showing
4 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import axios from 'axios' | ||
|
||
const urlRegex = | ||
// eslint-disable-next-line | ||
/(https:\/\/)(arweave\.net\/)([\w-]{43})/ | ||
|
||
export const arweaveDescriptionApi = { | ||
fetchArweaveFile: fetchArweaveFile, | ||
cancel: function () { | ||
if (this?.abortController) { | ||
this.abortController.abort() | ||
this.abortController = null | ||
} | ||
}, | ||
abortController: null, | ||
} | ||
async function fetchArweaveFile(url: string) { | ||
const controller = new AbortController() | ||
if (typeof this !== 'undefined') { | ||
this.abortController = controller | ||
} | ||
const pieces = url.match(urlRegex) | ||
console.log(pieces) | ||
if (pieces) { | ||
console.log(pieces) | ||
const idPiece = pieces[3] | ||
if (idPiece) { | ||
const apiUrl = 'https://arweave.net/' + idPiece | ||
const apiResponse = await axios.get(apiUrl, { | ||
signal: controller.signal, | ||
}) | ||
if (apiResponse.status === 200) { | ||
return apiResponse.data.description | ||
} else { | ||
console.warn('could not arweave file', { | ||
url, | ||
apiResponse: apiResponse.data, | ||
}) | ||
} | ||
} | ||
} | ||
|
||
return undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters