Skip to content

Commit

Permalink
Add save and update images
Browse files Browse the repository at this point in the history
  • Loading branch information
PhoenixNazarov committed Oct 1, 2024
1 parent 0d66437 commit 0bed478
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export default defineComponent({
required: true
}
},
data() {
return {
on: false
}
},
watch: {
model(newVal) {
this.doWrite(newVal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineComponent({
reader.readAsDataURL(file)
reader.onload = () => {
const bytes = reader?.result?.split(',')[1]
this.doWrite(bytes)
this.doWrite({type: 'bytes', value: bytes})
}
}
}
Expand All @@ -38,7 +38,12 @@ export default defineComponent({
@update:model-value="doWriteFile"
/>
<img
v-if="model"
v-if="(model as any)?.value"
:src="'data:image/png;base64,'+ (model as any).value"
:height="componentSchema.size ? CONST_SCHEMA_COMPONENT.image_size[componentSchema.size] : CONST_SCHEMA_COMPONENT.image_size_default"
/>
<img
v-else-if="model"
:src="'data:image/png;base64,'+ model"
:height="componentSchema.size ? CONST_SCHEMA_COMPONENT.image_size[componentSchema.size] : CONST_SCHEMA_COMPONENT.image_size_default"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export default defineComponent({
const columnDb = this.componentSchema.columns.find(el => {
return el.title == i.title
})
console.log(columnDb, i)
if (columnDb?.columnDbms) {
return columnDb?.columnDbms
}
Expand Down
18 changes: 15 additions & 3 deletions server/promptadmin_server/api/routers/project/tables/item.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Any

from fastapi import APIRouter
Expand All @@ -15,9 +16,14 @@ class LoadItemRequest(BaseModel):
id: int


class TypeColumn(BaseModel):
type: str
value: Any


class Column(BaseModel):
key: str
value: Any
value: TypeColumn | Any


class SaveItemRequest(LoadItemRequest):
Expand Down Expand Up @@ -47,6 +53,10 @@ async def update(save_item_request: SaveItemRequest):
if i > 0:
sql_statement += ', '
sql_statement += f'{save_item_request.columns[i].key} = ${i + 1}'
if isinstance(save_item_request.columns[i].value, TypeColumn):
if save_item_request.columns[i].value.type == 'bytes':
values.append(str(save_item_request.columns[i].value.value).encode())
continue
values.append(save_item_request.columns[i].value)

sql = f"""
Expand Down Expand Up @@ -74,15 +84,17 @@ async def create(save_item_request: SaveItemRequest):
sql_statement_values += ', '
sql_statement_columns += f'{save_item_request.columns[i].key}'
sql_statement_values += f'${i + 1}'
if isinstance(save_item_request.columns[i].value, TypeColumn):
if save_item_request.columns[i].value.type == 'bytes':
values.append(str(save_item_request.columns[i].value.value).encode())
continue
values.append(save_item_request.columns[i].value)

sql = f"""
insert into {save_item_request.table} ({sql_statement_columns})
values ({sql_statement_values})
returning id
"""
print(sql)
print(values)
return await connection.fetchrow(sql, *values)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ async def load(load_request: LoadRequest):
f'{limit} '
f'{offset} '
)
print(statement)
return await connection.fetch(statement)


Expand Down

0 comments on commit 0bed478

Please sign in to comment.