diff --git a/.vscode/extensions.json b/.vscode/extensions.json index b5c5ed5..753230b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -4,7 +4,7 @@ "ms-azuretools.vscode-docker", "wholroyd.jinja", "github.vscode-github-actions", - // "ms-python.python", - "bungcip.better-toml" + "bungcip.better-toml", + "ms-python.python" ] } \ No newline at end of file diff --git a/README.md b/README.md index a55fa12..55069ae 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ TODO explain where the motivation is coming from and what this intends to solve - Persist apps through sessions - Delete an app - Minify TailwindCSS output for production +- Update app with new manifest #### What is left out - Authentication and authorization - Therefore there is also no persistence of the database between deploys diff --git a/wappstore/data/models.py b/wappstore/data/models.py index 9469f3d..da48fd5 100644 --- a/wappstore/data/models.py +++ b/wappstore/data/models.py @@ -33,6 +33,9 @@ class App(Base): # Technically also a limited set we should check but don't categories = relationship( "Category", back_populates="apps", secondary=app_category) + + screenshots = relationship( + "Screenshot", back_populates="app", cascade="all, delete-orphan") # direction = Column(String, default="auto") # # The language of the manifests localizable members # language = Column(String, nullable=True) @@ -78,3 +81,17 @@ class Category(Base): def __str__(self): return self.name + + +class Screenshot(Base): + __tablename__ = "screenshots" + + id = Column(Integer, primary_key=True, index=True) + app_id = Column(String, ForeignKey("apps.id")) + source = Column(String) + # This should be split up later since it is not atomic to follow normalization rules + sizes = Column(String) + # This should refer to MIME types + type = Column(String) + + app = relationship("App", back_populates="screenshots") diff --git a/wappstore/main.py b/wappstore/main.py index 9744945..4d8deca 100644 --- a/wappstore/main.py +++ b/wappstore/main.py @@ -106,7 +106,8 @@ def view_app(request: Request, app_id: str, database: Session = Depends(get_data "id": web_app.id, "name": web_app.name, "description": web_app.description, - "source": source + "source": source, + "screenshots": web_app.screenshots }) @@ -120,6 +121,14 @@ def createIconFor(app_id: str): purpose=json.get("purpose", "any")) +def createScreenshotFor(app_id: str): + return lambda json: models.Screenshot( + app_id=app_id, + source=json["src"], + sizes=json["sizes"], + type=json["type"]) + + def extract_manifest_url(content: str): # Extract manifest url # We need to find something like but attributes can be in different order @@ -232,6 +241,10 @@ def create_app(request: Request, url: Annotated[str, Form(alias="url")], session categories = list(map(lambda category: models.Category( name=category), categories)) + # Persist screenshots + screenshots = list(map(createScreenshotFor(app_id), + manifest.get("screenshots", []))) + # Persist application to database web_app = models.App( id=app_id, @@ -240,7 +253,8 @@ def create_app(request: Request, url: Annotated[str, Form(alias="url")], session icons=icons, start_url=manifest["start_url"], description=manifest["description"], - categories=categories) + categories=categories, + screenshots=screenshots) crud.create_app(session, web_app) diff --git a/wappstore/templates/apps/detail.html b/wappstore/templates/apps/detail.html index 78431eb..d23dd6b 100644 --- a/wappstore/templates/apps/detail.html +++ b/wappstore/templates/apps/detail.html @@ -13,7 +13,7 @@