Added catch for HTTPError and added papermc ground work

Changes:
- Added HTTPError catch when searching for a plugin
- Created first ground work for papermc server jar support
This commit is contained in:
Neocky 2021-03-15 01:20:18 +01:00
parent 932ae66827
commit 20261d110e
2 changed files with 40 additions and 2 deletions

View File

@ -78,9 +78,15 @@ def searchPackage(ressourceName):
ressourceSelected = ressourceSelected - 1 ressourceSelected = ressourceSelected - 1
ressourceId = packageName[ressourceSelected]["id"] ressourceId = packageName[ressourceSelected]["id"]
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
try:
getSpecificPackage(ressourceId, checkConfig().sftp_folderPath) getSpecificPackage(ressourceId, checkConfig().sftp_folderPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
else: else:
try:
getSpecificPackage(ressourceId, checkConfig().pathToPluginFolder) getSpecificPackage(ressourceId, checkConfig().pathToPluginFolder)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'): def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):

View File

@ -0,0 +1,32 @@
import sys
from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest
from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection
def getInstalledPaperMinecraftVersion(localPaperName):
print("test")
def getInstalledPaperVersion(localPaperName):
print("test")
# https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config#/
def papermc_downloader(paperBuild, paperVersionGroup='1.16'):
url = f"https://papermc.io/api/v2/projects/paper/{serverVersion}/{inputPackageVersion}" # v1 is deprecated
#https://papermc.io/api/v2/projects/paper/version_group/1.16/builds get all builds for all 1.16 versions
#https://papermc.io/api/v2/projects/paper/versions/1.16.5/builds/450 gets file name
# input serverversion = 1.16.5 inputpackageversion = 450
# regex 1.16 % build url
# search for 450 in version group 1.16
# if found get file name from builds/450
# build url & download package
# https://papermc.io/api/v2/projects/paper/versions/1.16.5/builds/450/downloads/paper-1.16.5-450.jar
papermcdetails = doAPIRequest(url)
errorExists = papermcdetails["error"]
if errorExists in papermcdetails:
print(f"PaperMc version: {inputPackageVersion} couldn't be found")
print("Aborting the download of PaperMc.")
input("Press any key + enter to exit...")
sys.exit()