mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:46:30 +00:00
95 lines
2.7 KiB
Batchfile
95 lines
2.7 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
set RETRY_COUNT=0
|
|
set MAX_RETRIES=5
|
|
set SUCCESS=0
|
|
|
|
:: Get the current date and time using WMI
|
|
for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value') do (
|
|
set "dt=%%a"
|
|
)
|
|
set "LOG_DATE=!dt:~0,4!-!dt:~4,2!-!dt:~6,2!"
|
|
set "LOG_TIME=!dt:~8,2!:!dt:~10,2!:!dt:~12,2!"
|
|
|
|
set "LOG_MESSAGE=echo [!LOG_DATE! !LOG_TIME!] !*"
|
|
|
|
:: Save the current directory and move to the script's location.
|
|
set CURRENT_DIR=%cd%
|
|
cd /d %~dp0..
|
|
|
|
:: Define API variables
|
|
set API_URL=https://api.azaion.com
|
|
set RESOURCES_FOLDER=%1
|
|
set EMAIL=uploader@azaion.com
|
|
set PASSWORD=Az@1on_10Upl0@der
|
|
|
|
:: Find the file to upload
|
|
set "UPLOAD_FILE="
|
|
for /f "delims=" %%i in ('dir /b /a-d "AzaionSuite.Iterative*"') do (
|
|
if not defined UPLOAD_FILE set "UPLOAD_FILE=%%i"
|
|
)
|
|
|
|
if not defined UPLOAD_FILE (
|
|
%LOG_MESSAGE% [ERROR] No matching file found for upload.
|
|
exit /b 1
|
|
)
|
|
|
|
echo.
|
|
%LOG_MESSAGE% === Starting AzaionSuite Upload Script ===
|
|
echo.
|
|
%LOG_MESSAGE% [INFO] Logging in and retrieving token...
|
|
for /f "tokens=*" %%i in ('curl -s -X POST -H "Content-Type: application/json" ^
|
|
-d "{\"email\":\"%EMAIL%\",\"password\":\"%PASSWORD%\"}" %API_URL%/login') do set RESPONSE=%%i
|
|
|
|
%LOG_MESSAGE% [DEBUG] API Login Response: !RESPONSE!
|
|
|
|
for /f "tokens=2 delims=:" %%a in ('echo !RESPONSE! ^| findstr /i "token"') do (
|
|
set "TOKEN=%%a"
|
|
set "TOKEN=!TOKEN:~1,-1!"
|
|
set "TOKEN=!TOKEN:~0,-2!"
|
|
)
|
|
|
|
if not defined TOKEN (
|
|
%LOG_MESSAGE% [ERROR] Failed to retrieve authentication token. Exiting.
|
|
exit /b 1
|
|
)
|
|
%LOG_MESSAGE% [INFO] Login successful.
|
|
|
|
echo.
|
|
%LOG_MESSAGE% [INFO] Clearing resources folder: %RESOURCES_FOLDER%
|
|
curl -s -X POST %API_URL%/resources/clear/%RESOURCES_FOLDER% -d {} -H "Authorization: Bearer !TOKEN!"
|
|
echo.
|
|
%LOG_MESSAGE% [INFO] Folder clear command sent.
|
|
|
|
:RETRY_UPLOAD
|
|
set /a RETRY_COUNT+=1
|
|
echo.
|
|
%LOG_MESSAGE% [INFO] Attempting to upload file: %UPLOAD_FILE% (Attempt !RETRY_COUNT! of !MAX_RETRIES!)
|
|
|
|
curl --location --fail %API_URL%/resources/%RESOURCES_FOLDER% ^
|
|
-H "Authorization: Bearer !TOKEN!" ^
|
|
-H "Content-Type: multipart/form-data" ^
|
|
--form "data=@%UPLOAD_FILE%" >NUL && set SUCCESS=1
|
|
|
|
if "!SUCCESS!"=="1" (
|
|
echo.
|
|
%LOG_MESSAGE% [SUCCESS] File uploaded successfully on attempt !RETRY_COUNT!.
|
|
goto UPLOAD_DONE
|
|
) else (
|
|
echo.
|
|
%LOG_MESSAGE% [ERROR] Upload failed on attempt !RETRY_COUNT!.
|
|
if !RETRY_COUNT! lss !MAX_RETRIES! (
|
|
%LOG_MESSAGE% [INFO] Waiting 10 seconds before retrying...
|
|
timeout /t 10 /nobreak >NUL
|
|
goto RETRY_UPLOAD
|
|
) else (
|
|
%LOG_MESSAGE% [FATAL] All upload attempts failed. The Jenkins job will now fail.
|
|
exit /b 1
|
|
)
|
|
)
|
|
|
|
:UPLOAD_DONE
|
|
cd /d %CURRENT_DIR%
|
|
echo.
|
|
%LOG_MESSAGE% === Script execution complete. ===
|