@@ -32,7 +32,7 @@ require('ethernaut-oso')
3232require ( 'ethernaut-ai-ui' )
3333require ( 'ethernaut-optigov' )
3434
35- const OPTIMISM_TIMESTAMP =
35+ const OP_REMOTE_FILE =
3636 'https://github.com/raiseerco/ethernaut-app-kb/releases/download/daily/last-update.json'
3737const ZIP_URL_OPTIMISM =
3838 'https://github.com/raiseerco/ethernaut-app-kb/releases/download/daily/kb.zip'
@@ -41,7 +41,7 @@ const FILES_DIR = path.join(
4141 '../../packages/ethernaut-ai/src/internal/assistants/docs/kb-files' ,
4242)
4343
44- const TIMESTAMP_FILE = path . join ( FILES_DIR , 'last-update.json' )
44+ const OP_LOCAL_FILE = path . join ( FILES_DIR , 'last-update.json' )
4545
4646async function downloadFile ( url ) {
4747 const response = await fetch ( url )
@@ -53,17 +53,17 @@ async function downloadFile(url) {
5353 return response . text ( )
5454}
5555
56- let localTimestamp = null
56+ let localHash = null
5757
5858async function checkKB ( ) {
5959 try {
60- if ( fs . existsSync ( TIMESTAMP_FILE ) ) {
60+ if ( fs . existsSync ( OP_LOCAL_FILE ) ) {
6161 try {
62- const timestampData = fs . readFileSync ( TIMESTAMP_FILE , 'utf8' )
63- localTimestamp = JSON . parse ( timestampData )
64- const timestampRepo = await downloadFile ( OPTIMISM_TIMESTAMP )
65- const parsedData = JSON . parse ( timestampRepo )
66- if ( parsedData . last_update === localTimestamp . last_update ) {
62+ const localOpFile = fs . readFileSync ( OP_LOCAL_FILE , 'utf8' )
63+ localHash = JSON . parse ( localOpFile )
64+ const remoteOpFile = await downloadFile ( OP_REMOTE_FILE )
65+ const remoteHash = JSON . parse ( remoteOpFile )
66+ if ( remoteHash . last_commit === localHash . last_commit ) {
6767 // spinner.success('--- KB already up to date')
6868 return
6969 } else {
@@ -105,9 +105,9 @@ async function downloadKB() {
105105 fs . unlinkSync ( tempZipPath )
106106
107107 try {
108- const timestampData = await downloadFile ( OPTIMISM_TIMESTAMP )
108+ const timestampData = await downloadFile ( OP_REMOTE_FILE )
109109 const parsedData = JSON . parse ( timestampData )
110- fs . writeFileSync ( TIMESTAMP_FILE , JSON . stringify ( parsedData , null , 2 ) )
110+ fs . writeFileSync ( OP_LOCAL_FILE , JSON . stringify ( parsedData , null , 2 ) )
111111 } catch ( error ) {
112112 console . error ( 'Error downloading or parsing timestamp file:' , error )
113113 }
0 commit comments