This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andreas Richter <[email protected]>
- Loading branch information
Showing
12 changed files
with
5,861 additions
and
6,316 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
nodeLinker: node-modules | ||
compressionLevel: mixed | ||
|
||
enableGlobalCache: false | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs | ||
spec: "@yarnpkg/plugin-interactive-tools" | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.6.1.cjs | ||
yarnPath: .yarn/releases/yarn-4.0.1.cjs |
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
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 was deleted.
Oops, something went wrong.
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,71 @@ | ||
export const resolveUrl = (url: string) => { | ||
const resolver = new UrlResolver([['ipfs://', IPFS_URL]]) | ||
|
||
return resolver.resolveUrl(url) | ||
} | ||
|
||
// TODO refactor this when below classes will be published in own repo | ||
|
||
export class UrlConverter { | ||
protected destination: string | ||
protected match?: RegExp | string | ||
|
||
constructor(destination: string | URL, match?: RegExp | string) { | ||
this.destination = | ||
destination instanceof URL ? destination.toString() : destination | ||
if (this.destination.at(-1) != '/') { | ||
this.destination += '/' | ||
} | ||
this.match = match | ||
} | ||
|
||
resolveUrl(match: RegExp | string, url: string): string { | ||
match = this.match || match | ||
return url.replaceAll(match, this.destination.toString()) | ||
} | ||
} | ||
|
||
export class UrlResolver { | ||
private converters: Array<{ | ||
match: string | RegExp | ||
converter: UrlConverter | ||
}> = [] | ||
constructor(converters: Array<[string | RegExp, UrlConverter | string]>) { | ||
for (const item of converters) { | ||
const [match, _converter] = item | ||
if (match == undefined) { | ||
throw new TypeError('Match criteria not defined') | ||
} | ||
const converter = | ||
typeof _converter === 'string' | ||
? new UrlConverter(_converter) | ||
: _converter | ||
if (!(converter instanceof UrlConverter)) { | ||
throw new TypeError('Invalid converter') | ||
} | ||
this.converters.push({ match, converter }) | ||
} | ||
} | ||
|
||
resolveUrl(url: string): string { | ||
const current = new Set<{ | ||
match: string | RegExp | ||
converter: UrlConverter | ||
}>(this.converters) | ||
let found = true | ||
while (found) { | ||
found = false | ||
for (const entry of current) { | ||
const { match, converter } = entry | ||
if (match instanceof RegExp ? match.test(url) : url.startsWith(match)) { | ||
url = converter.resolveUrl(match, url) | ||
// This converter matches, so don't use it again. | ||
current.delete(entry) | ||
found = true | ||
break | ||
} | ||
} | ||
} | ||
return url | ||
} | ||
} |
Oops, something went wrong.