@@ -12,14 +12,15 @@ import { GitClient } from "./git"
1212import { expandFiles } from "./fs"
1313import { join } from "node:path"
1414import { isCancelError } from "./error"
15+ import { GITHUB_ASSET_URL_RX } from "./constants"
1516const dbg = genaiscriptDebug ( "res" )
1617const dbgAdaptors = dbg . extend ( "adaptors" )
1718const dbgFiles = dbg . extend ( "files" )
1819dbgFiles . enabled = false
1920
2021const urlAdapters : {
2122 id : string
22- matcher : ( url : string ) => string
23+ matcher : ( url : string ) => Awaitable < string >
2324} [ ] = [
2425 {
2526 id : "github blob" ,
@@ -40,6 +41,17 @@ const urlAdapters: {
4041 : undefined
4142 } ,
4243 } ,
44+ {
45+ id : "github assets" ,
46+ matcher : async ( url ) => {
47+ if ( GITHUB_ASSET_URL_RX . test ( url ) ) {
48+ const client = GitHubClient . default ( )
49+ const resolved = await client . resolveAssetUrl ( url )
50+ return resolved
51+ }
52+ return undefined
53+ } ,
54+ } ,
4355 {
4456 id : "gist" ,
4557 matcher : ( url ) => {
@@ -54,10 +66,10 @@ const urlAdapters: {
5466 } ,
5567]
5668
57- function applyUrlAdapters ( url : string ) {
69+ async function applyUrlAdapters ( url : string ) {
5870 // Use URL adapters to modify the URL if needed
5971 for ( const a of urlAdapters ) {
60- const newUrl = a . matcher ( url )
72+ const newUrl = await a . matcher ( url )
6173 if ( newUrl ) {
6274 dbgAdaptors ( `%s: %s` , a . id , uriRedact ( url ) )
6375 return newUrl
@@ -83,7 +95,6 @@ const uriResolvers: Record<
8395 // https://.../.../....git
8496 if ( / \. g i t ( $ | \/ ) / . test ( url . pathname ) )
8597 return await uriResolvers . git ( dbg , url , options )
86-
8798 // regular fetch
8899 const fetch = await createFetch ( options )
89100 dbg ( `fetch %s` , uriRedact ( url . href ) )
@@ -211,7 +222,7 @@ export async function tryResolveResource(
211222 options ?: TraceOptions & CancellationOptions
212223) : Promise < { uri : URL ; files : WorkspaceFile [ ] } | undefined > {
213224 if ( ! url ) return undefined
214- url = applyUrlAdapters ( url )
225+ url = await applyUrlAdapters ( url )
215226 const uri = uriTryParse ( url )
216227 if ( ! uri ) return undefined
217228 const { cancellationToken } = options || { }
0 commit comments