Added the AssetUploader

This commit is contained in:
Mathias Wagner 2022-07-19 21:13:42 +02:00
parent 4b9abfd36d
commit 28e8171183
7 changed files with 224 additions and 0 deletions

View File

@ -0,0 +1,109 @@
name: Build
on:
push:
branches: [master]
jobs:
createrelease:
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Create Version
uses: paulhatch/semantic-version@v4.0.2
id: create_version
with:
tag_prefix: "v"
major_pattern: "(MAJOR)"
minor_pattern: "(MINOR)"
format: "${major}.${minor}.${patch}-prerelease${increment}"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.create_version.outputs.version_tag }}
release_name: Release ${{ steps.create_version.outputs.version_tag }}
draft: false
prerelease: false
- name: Output Release URL File
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
- name: Save Release URL File for publish
uses: actions/upload-artifact@v1
with:
name: release_url
path: release_url.txt
build:
name: Build packages
needs: createrelease
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
TARGET: macos
CMD_BUILD: pyinstaller --noconfirm --onefile --noconsole --icon "logo.ico" main.py && cd dist && zip -r9 main main.app/
OUT_FILE_NAME: main.zip
ASSET_NAME: app-macos.zip
OS_DEP_CMD: echo no additional dependencies needed
ASSET_MIME: application/zip
- os: ubuntu-latest
TARGET: linux
OS_DEP_CMD: sudo apt-get install python3-pyqt5 pyqt5-dev-tools qttools5-dev-tools
CMD_BUILD: pyinstaller --noconfirm --onefile --noconsole --icon "logo.ico" main.py
OUT_FILE_NAME: main
ASSET_NAME: main-linux
ASSET_MIME: application/x-executable
- os: windows-latest
TARGET: windows
OS_DEP_CMD: echo no additional dependencies needed
CMD_BUILD: pyinstaller --noconfirm --onefile --noconsole --icon "logo.ico" main.py
OUT_FILE_NAME: main.exe
ASSET_NAME: main-windows.exe
ASSET_MIME: application/vnd.microsoft.portable-executable
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyperclip requests PyQt5 pyqt5 pyqt5-sip pyinstaller
- name: Install additional dependencies
run: ${{matrix.OS_DEP_CMD}}
- name: Build with pyinstaller for ${{matrix.TARGET}}
run: ${{matrix.CMD_BUILD}}
- name: Load Release URL File from release job
uses: actions/download-artifact@v1
with:
name: release_url
- name: Get Release File Name & Upload URL
id: get_release_info
shell: bash
run: |
value=`cat release_url/release_url.txt`
echo ::set-output name=upload_url::$value
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: ./dist/${{ matrix.OUT_FILE_NAME}}
asset_name: ${{ matrix.ASSET_NAME}}
asset_content_type: ${{ matrix.ASSET_MIME}}

3
AssetUploaderV1/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Project exclude paths
/venv/
/.idea/

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
AssetUploaderV1/logo.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

112
AssetUploaderV1/main.py Normal file
View File

@ -0,0 +1,112 @@
import os
import sys
import pyperclip
import requests
from PyQt5.QtCore import QCoreApplication, QRect, QMetaObject
from PyQt5.QtWidgets import QPushButton, QApplication, QDialog, QFileDialog, QLineEdit, QMessageBox, QInputDialog
sheepstar_post = "https://api.sheepstar.xyz/media/"
def sendError(title, text):
QMessageBox().critical(None, title, text)
def sendSuccess(title, text):
QMessageBox().information(None, title, text)
def deleteFile():
assetID, _ = QInputDialog().getText(None, "Datei von CDN löschen",
"Gib hier die 16-stellige assetID ein, um es löschen zu können.")
headers = {'Authorization': "Bearer " + open('api-key.txt', 'r').read().replace("\n", "")}
post = requests.delete(sheepstar_post + "/delete", headers=headers, data={'assetID': assetID})
try:
if post.status_code == 200:
sendSuccess("Löschen erfolgreich", "Die Datei wurde erfolgreich aus dem CDN gelöscht.")
elif post.status_code == 401:
sendError("Löschen fehlgeschlagen", "Bitte ersetze den API-Key in der api-key.txt")
elif post.status_code == 404:
sendError("Löschen fehlgeschlagen", "Die Datei existiert nicht auf dem server.")
elif post.status_code == 500:
sendError("Löschen fehlgeschlagen", "Ein interner Fehler ist aufgetreten.")
except Exception as e:
sendError("Löschen fehlgeschlagen", "Ein unbekannter Fehler ist aufgetreten: " + str(e))
class Ui_Dialog(object):
def setupUi(self, Dialog):
if not Dialog.objectName():
Dialog.setObjectName(u"Dialog")
Dialog.resize(385, 88)
Dialog.setMaximumWidth(385)
Dialog.setMaximumHeight(88)
Dialog.setMinimumWidth(385)
Dialog.setMinimumHeight(88)
self.lineEdit = QLineEdit(Dialog)
self.lineEdit.setObjectName(u"lineEdit")
self.lineEdit.setEnabled(False)
self.lineEdit.setGeometry(QRect(10, 10, 271, 31))
self.pushButton = QPushButton(Dialog)
self.pushButton.setObjectName(u"pushButton")
self.pushButton.setGeometry(QRect(290, 10, 95, 30))
self.pushButton.clicked.connect(self.select)
self.pushButton_2 = QPushButton(Dialog)
self.pushButton_2.setObjectName(u"pushButton_2")
self.pushButton_2.setGeometry(QRect(10, 50, 200, 35))
self.pushButton_2.clicked.connect(self.upload)
self.pushButton_3 = QPushButton(Dialog)
self.pushButton_3.setObjectName(u"pushButton_3")
self.pushButton_3.setGeometry(QRect(215, 50, 170, 35))
self.pushButton_3.clicked.connect(deleteFile)
self.retranslateUi(Dialog)
QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Sheepstar Asset Uploader", None))
self.pushButton.setText(QCoreApplication.translate("Dialog", u"Auswählen", None))
self.pushButton_2.setText(QCoreApplication.translate("Dialog", u"Hochladen", None))
self.pushButton_3.setText(QCoreApplication.translate("Dialog", u"Datei löschen", None))
def select(self):
file_name, _ = QFileDialog.getOpenFileName(None, "Open File")
self.lineEdit.setText(file_name)
def upload(self):
upload_file = self.lineEdit.text()
if os.path.isfile(upload_file):
try:
files = {'asset': open(upload_file, 'rb')}
headers = {'Authorization': "Bearer " + open('api-key.txt', 'r').read().replace("\n", "")}
post = requests.put(sheepstar_post + "/upload", files=files, headers=headers)
if post.status_code == 400:
sendError("Upload fehlgeschlagen", "Die Datei konnte nicht hochgeladen werden.")
elif post.status_code == 401:
sendError("Upload fehlgeschlagen", "Bitte ersetze den API-Key in der api-key.txt")
elif post.status_code == 200:
pyperclip.copy(post.json()['url'])
sendSuccess("Upload erfolgreich", "Der Link der Datei wurde in deine Zwischenablage kopiert.")
except Exception as e:
sendError("Upload fehlgeschlagen", "Es ist ein Fehler während des Uploads aufgetreten: " + str(e))
else:
sendError("Upload fehlgeschlagen", "Die Datei existiert nicht mehr auf deinem Computer")
if __name__ == "__main__":
if not os.path.exists('api-key.txt'):
f = open('api-key.txt', 'w')
f.write('replace this text with your api key')
f.close()
app = QApplication(sys.argv)
window = QDialog()
ui = Ui_Dialog()
ui.setupUi(window)
window.show()
sys.exit(app.exec_())