Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Create github release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 1 addition & 2 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from datetime import datetime, timezone

from pydantic import BaseModel, Field

from lnbits.db import FilterModel
from pydantic import BaseModel, Field


class CreateInventory(BaseModel):
Expand Down
21 changes: 6 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "lnbits-inventory"
name = "inventory"
version = "0.0.0"
requires-python = ">=3.10,<3.13"
description = "Shared Inventory extension"
Expand All @@ -8,8 +8,8 @@ urls = { Homepage = "https://lnbits.com", Repository = "https://github.com/lnbit

dependencies = [ "lnbits>1" ]

[tool.uv]
dev-dependencies = [
[dependency-groups]
dev = [
"black",
"pytest-asyncio",
"pytest",
Expand All @@ -18,6 +18,9 @@ dev-dependencies = [
"ruff",
]

[tool.poetry]
package-mode = false

[tool.mypy]
exclude = "(nostr/*)"
plugins = ["pydantic.mypy"]
Expand All @@ -28,18 +31,6 @@ init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true

[[tool.mypy.overrides]]
module = [
"lnbits.*",
"lnurl.*",
"loguru.*",
"fastapi.*",
"pydantic.*",
"pyqrcode.*",
"shortuuid.*",
"httpx.*",
]
ignore_missing_imports = "True"

[tool.pytest.ini_options]
log_cli = false
Expand Down
36 changes: 24 additions & 12 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,26 +555,38 @@ window.app = Vue.createApp({
}
},
async updateItem(data) {
const newPhotos = this.itemDialog.gallery.filter(p => p.isNew && p.file)
let newAssetIds = []
const filesToUpload = this.itemDialog.gallery
.filter(
p =>
(p.isNew && p.file) ||
(!p.isNew && p.assetId && isBase64String(p.assetId))
)
.map(p => {
if (p.isNew && p.file) return p.file
if (!p.isNew && p.assetId && isBase64String(p.assetId))
return base64ToFile(p.assetId)
return null
})
.filter(Boolean)

if (newPhotos.length > 0) {
let uploadedAssetIds = []
if (filesToUpload.length > 0) {
try {
newAssetIds = await Promise.all(
newPhotos.map(p => this.uploadPhoto(p.file))
uploadedAssetIds = await Promise.all(
filesToUpload.map(file => this.uploadPhoto(file))
)
} catch (error) {
LNbits.utils.notifyError('Failed to upload new photos')
LNbits.utils.notifyError('Failed to upload photos')
return
}
}

const finalIds = [
...this.itemDialog.gallery
.filter(p => !p.isNew && p.assetId)
.map(p => p.assetId),
...newAssetIds
]
// Asset IDs from gallery that are not new and not base64
const existingAssetIds = this.itemDialog.gallery
.filter(p => !p.isNew && p.assetId && !isBase64String(p.assetId))
.map(p => p.assetId)

const finalIds = [...existingAssetIds, ...uploadedAssetIds]

data.images = toCsv(finalIds)

Expand Down
12 changes: 12 additions & 0 deletions static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ function fileToBase64(file) {
})
}

function base64ToFile(base64String, filename) {
const arr = base64String.split(',')
const mime = arr[0].match(/:(.*?);/)[1]
const bstr = atob(arr[1])
let n = bstr.length
const u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new File([u8arr], filename, {type: mime})
}

function isBase64String(str) {
if (typeof str !== 'string') return false
return str.includes('data:') && str.includes('base64')
Expand Down
77 changes: 46 additions & 31 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.