@@ -64,10 +64,13 @@ async function getBaseWebUICacheDir(): Promise<string> {
6464
6565/**
6666 * Determines the specific version directory name based on configuration.
67- * @returns {string } "nightly" or the specific WebUICoreVersion.
67+ * @returns {Promise< string> } "nightly-$hashOfLastModifiedNightly " or the specific WebUICoreVersion.
6868 */
69- function getVersionDirName ( ) : string {
70- return useNightly ? "nightly" : WebUICoreVersion ;
69+ async function getVersionDirName ( ) : Promise < string > {
70+ if ( useNightly ) {
71+ return `nightly-${ await getlLastModifedNightlyDateAsHash ( ) } ` ;
72+ }
73+ return WebUICoreVersion ;
7174}
7275
7376// --- Download and Extraction Logic ---
@@ -93,8 +96,8 @@ async function downloadAndExtractLibrary(
9396 const versionCacheDir = dirname ( targetLibPath ) ;
9497
9598 // Determine download URL
96- const version = getVersionDirName ( ) ; // Get "nightly" or the specific version string
97- const baseUrl = version === "nightly"
99+ const version = await getVersionDirName ( ) ; // Get "nightly-$hashOfLastModifiedNightlyRelease " or the specific version string
100+ const baseUrl = version . startsWith ( "nightly" )
98101 ? `https://github.com/webui-dev/webui/releases/download/nightly/`
99102 : `https://github.com/webui-dev/webui/releases/download/${ version } /` ;
100103
@@ -185,8 +188,8 @@ export async function ensureWebUiLib(baseLibName: string): Promise<string> {
185188 // 1. Get the base cache directory (e.g., ~/.cache/deno_webui)
186189 const baseWebUICacheDir = await getBaseWebUICacheDir ( ) ;
187190
188- // 2. Determine the version-specific subdirectory name ("nightly" or "2.5.0-beta.3")
189- const versionDirName = getVersionDirName ( ) ;
191+ // 2. Determine the version-specific subdirectory name ("nightly-$hashOfTheLastModifiedNighylyDate " or "2.5.0-beta.3")
192+ const versionDirName = await getVersionDirName ( ) ;
190193
191194 // 3. Construct the path to the version-specific cache directory
192195 const versionCacheDir = join ( baseWebUICacheDir , versionDirName ) ;
@@ -278,3 +281,47 @@ export function fromCString(value: Uint8Array): string {
278281}
279282
280283export class WebUIError extends Error { }
284+
285+ async function getlLastModifedNightlyDateAsHash ( ) {
286+ // it doesn't matter that we're using a specific build, its just to determine last modificaiton date
287+ const url =
288+ "https://github.com/webui-dev/webui/releases/download/nightly/webui-linux-gcc-x64.zip" ;
289+ try {
290+ // Perform a HEAD request to get only the headers
291+ const response = await fetch ( url , {
292+ method : "HEAD" ,
293+ } ) ;
294+
295+ if ( response . ok ) {
296+ const headers = response . headers ;
297+
298+ const lastModified = headers . get ( "last-modified" ) ;
299+
300+ if ( lastModified ) {
301+ const encoder = new TextEncoder ( ) ;
302+ const data = encoder . encode ( lastModified ) ;
303+
304+ // Calculate the SHA-256 hash
305+ const hashBuffer = await crypto . subtle . digest ( "SHA-256" , data ) ;
306+
307+ // Hash it
308+ return Array . from (
309+ new Uint8Array ( hashBuffer ) ,
310+ ( byte ) => byte . toString ( 16 ) . padStart ( 2 , "0" ) ,
311+ )
312+ . join ( "" )
313+ . slice ( 0 , 8 ) ;
314+ } else {
315+ throw new Error (
316+ "could not find last-modified header in nightly release" ,
317+ ) ;
318+ }
319+ } else {
320+ throw new Error (
321+ `Error fetching headers: ${ response . status } ${ response . statusText } ` ,
322+ ) ;
323+ }
324+ } catch ( error ) {
325+ throw new Error ( "Network error: " + error ) ;
326+ }
327+ }
0 commit comments