mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
add --with-screenshot option for app_manifest + rename 'image' key to 'screenshot'
This commit is contained in:
parent
b17e00c31e
commit
6ae9108dec
2 changed files with 9 additions and 5 deletions
|
@ -807,6 +807,10 @@ app:
|
||||||
arguments:
|
arguments:
|
||||||
app:
|
app:
|
||||||
help: Name, local path or git URL of the app to fetch the manifest of
|
help: Name, local path or git URL of the app to fetch the manifest of
|
||||||
|
-s:
|
||||||
|
full: --with-screenshot
|
||||||
|
help: Also return a base64 screenshot if any (API only)
|
||||||
|
action: store_true
|
||||||
|
|
||||||
### app_list()
|
### app_list()
|
||||||
list:
|
list:
|
||||||
|
|
10
src/app.py
10
src/app.py
|
@ -817,7 +817,7 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
|
||||||
logger.success(m18n.n("upgrade_complete"))
|
logger.success(m18n.n("upgrade_complete"))
|
||||||
|
|
||||||
|
|
||||||
def app_manifest(app):
|
def app_manifest(app, with_screenshot=False):
|
||||||
|
|
||||||
manifest, extracted_app_folder = _extract_app(app)
|
manifest, extracted_app_folder = _extract_app(app)
|
||||||
|
|
||||||
|
@ -825,20 +825,20 @@ def app_manifest(app):
|
||||||
manifest["install"] = hydrate_questions_with_choices(raw_questions)
|
manifest["install"] = hydrate_questions_with_choices(raw_questions)
|
||||||
|
|
||||||
# Add a base64 image to be displayed in web-admin
|
# Add a base64 image to be displayed in web-admin
|
||||||
if Moulinette.interface.type == "api":
|
if with_screenshot and Moulinette.interface.type == "api":
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
manifest["image"] = None
|
manifest["screenshot"] = None
|
||||||
screenshots_folder = os.path.join(extracted_app_folder, "doc", "screenshots")
|
screenshots_folder = os.path.join(extracted_app_folder, "doc", "screenshots")
|
||||||
|
|
||||||
if os.path.exists(screenshots_folder):
|
if os.path.exists(screenshots_folder):
|
||||||
with os.scandir(screenshots_folder) as it:
|
with os.scandir(screenshots_folder) as it:
|
||||||
for entry in it:
|
for entry in it:
|
||||||
ext = os.path.splitext(entry.name)[1].replace(".", "").lower()
|
ext = os.path.splitext(entry.name)[1].replace(".", "").lower()
|
||||||
if entry.is_file() and ext in ("png", "jpg", "jpeg", "webp"):
|
if entry.is_file() and ext in ("png", "jpg", "jpeg", "webp", "gif"):
|
||||||
with open(entry.path, "rb") as img_file:
|
with open(entry.path, "rb") as img_file:
|
||||||
data = base64.b64encode(img_file.read()).decode("utf-8")
|
data = base64.b64encode(img_file.read()).decode("utf-8")
|
||||||
manifest["image"] = f"data:image/{ext};charset=utf-8;base64,{data}"
|
manifest["screenshot"] = f"data:image/{ext};charset=utf-8;base64,{data}"
|
||||||
break
|
break
|
||||||
|
|
||||||
shutil.rmtree(extracted_app_folder)
|
shutil.rmtree(extracted_app_folder)
|
||||||
|
|
Loading…
Add table
Reference in a new issue