Skip to content

Commit

Permalink
added ownerinfo @ templatetree
Browse files Browse the repository at this point in the history
  • Loading branch information
pandadiestro committed Dec 1, 2024
1 parent e9f0fae commit e8c71d3
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 37 deletions.
39 changes: 12 additions & 27 deletions stiller-backend/db/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ create table file (
ext text not null,
hashed integer not null,
size real not null,
deleted integer not null
deleted integer not null default 0
);

create table tier (
Expand Down Expand Up @@ -42,38 +42,13 @@ create table metatemplatefile (

create table template (
id integer unique primary key autoincrement not null,
owner integer not null references user (id),
tier integer not null references tier (id),
templatefile integer not null references metatemplatefile(id),
title text not null,
description text not null
);

-- casafugaz.metatemplate
-- - escenario 3d (.blend, .obj)
-- - slots -> slot: ref=10 type=3d (.json)
-- - topdown_view (.svg)

-- Crear galería a partir de template t:
-- - select * from template where id = t;
-- - template = file.Open(res)
-- - parsear template -> escenario, *slots, topdown
-- - INSERT gallery;
-- - for slot of slots INSERT galleryslot;

-- Saber cómo renderizar la galería
-- - slots (.json)
-- - topdown_view (.svg)
-- GET gallery/2d/casa-fugaz
-- - select * from gallery where slug = 'casa-fugaz' join template;
-- - template = file.Open(res)
-- - parsear template -> escenario, *slots, *topdown
-- - return json

-- GET gallery/3d/casa-fugaz
-- - slots (.json)
-- - topdown_view (.svg)
-- - lo mismo

create table galleryslot (
gallery integer not null references gallery (id),
slotid text not null,
Expand All @@ -86,11 +61,21 @@ create table gallery (
id integer unique primary key autoincrement not null,
owner integer not null references user (id),
template integer not null references template (id),
deleted integer not null default 0,
slug text unique not null,
title text,
description text
);

table gallery_telem (
id integer unique primary key autoincrement not null,
gallery integer not null references gallery (id),
user integer not null references user (id),
user_agent text not null,
load_time real not null,
used_time real not null default 0
)

insert into
filetype
values
Expand Down
95 changes: 95 additions & 0 deletions stiller-backend/db/create.sql.new
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
create table filetype (
code integer unique primary key not null,
name text unique not null
);

create table file (
id integer unique primary key autoincrement not null,
owner integer not null references user (id),
type integer not null references filetype (code),
path text unique not null,
filename text not null,
title text,
description text,
ext text not null,
hashed integer not null,
size real not null,
--new default
deleted integer not null default 0
);

create table tier (
id integer unique primary key not null,
name text unique not null
);

create table user (
id integer unique primary key autoincrement not null,
tier integer not null references tier (id),
displayname text not null,
username text unique not null,
mail text not null,
bpasswd text not null
);

create table avatar (
user integer not null references user (id),
file integer not null references file (id)
);

create table metatemplatefile (
id integer unique primary key autoincrement not null
);

create table template (
id integer unique primary key autoincrement not null,
tier integer not null references tier (id),
templatefile integer not null references metatemplatefile(id),
title text not null,
description text not null
);

create table galleryslot (
gallery integer not null references gallery (id),
slotid text not null,
res integer references file (id),
title text,
description text
);

create table gallery (
id integer unique primary key autoincrement not null,
owner integer not null references user (id),
template integer not null references template (id),
slug text unique not null,
title text,
description text,
--new
deleted integer not null default 0
);


--new table
table gallery_telem (
id integer unique primary key autoincrement not null,
gallery integer not null references gallery (id),
user integer not null references user (id),
user_agent text not null,
load_time real not null,
used_time real not null default 0
)

insert into
filetype
values
(0, 'image'),
(1, 'video'),
(2, 'object3d');

insert into
tier
values
(0, 'free'),
(1, 'van gogh'),
(2, 'picasso');

39 changes: 30 additions & 9 deletions stiller-backend/internal/handlers/get_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ func GetTemplate(w http.ResponseWriter, r *http.Request, params httprouter.Param
return
}

type Pair struct {
dbutils.StillerUser `json:"owner"`
dbutils.StillerTemplate
}

type ResPayload []Pair

user_token := r.Header.Get("token")
user_decoded, token_decode_err := jwt.Decode(user_token)
if loggers.RequestLog(token_decode_err, "", http.StatusUnauthorized, &w) {
Expand Down Expand Up @@ -63,23 +70,37 @@ func GetTemplate(w http.ResponseWriter, r *http.Request, params httprouter.Param
}

gettemplates_stmt := sqlf.
Select("*").
Select("template.id as temp_id").
Select("template.tier as temp_tier").
Select("template.templatefile as temp_file").
Select("template.title as temp_title").
Select("template.templatefile as temp_templatefile").
Select("template.description as temp_description").
Select("user.*").
From("template").
Where("tier <= ?", tier)
Join("user", "user.id = owner").
Where("template.tier <= ?", tier)

templates := make([]dbutils.StillerTemplate, 0, 2)
templates := make([]Pair, 0, 2)

templateexec_err := sqlitex.ExecuteTransient(dbconn, gettemplates_stmt.String(), &sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
new_template := dbutils.StillerTemplate{
Id: int(stmt.GetInt64("id")),
TierId: int(stmt.GetInt64("tier")),
TemplateId: int(stmt.GetInt64("template")),
Title: stmt.GetText("title"),
Description: stmt.GetText("description"),
Id: int(stmt.GetInt64("temp_id")),
TierId: int(stmt.GetInt64("temp_tier")),
TemplateId: int(stmt.GetInt64("temp_templatefile")),
Title: stmt.GetText("temp_title"),
Description: stmt.GetText("temp_description"),
}

templates = append(templates, new_template)
new_user := dbutils.StillerUser{}
new_user.FromStmt(stmt)
new_user.Bpasswd = ""

templates = append(templates, Pair{
StillerUser: new_user,
StillerTemplate: new_template,
})
return nil
},

Expand Down
27 changes: 26 additions & 1 deletion stiller-backend/pkg/dbutils/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package dbutils

import "stiller/pkg/templates"
import (
"stiller/pkg/templates"

"zombiezen.com/go/sqlite"
)

type StillerFileType uint8
const (
Expand Down Expand Up @@ -43,6 +47,17 @@ type StillerUser struct {
Bpasswd string `json:"bpasswd,omitempty"`
}

func (su *StillerUser) FromStmt(stmt *sqlite.Stmt) {
*su = StillerUser{
Id: int(stmt.GetInt64("id")),
TierId: StillerTier(stmt.GetInt64("tier")),
Displayname: stmt.GetText("displayname"),
Username: stmt.GetText("username"),
Mail: stmt.GetText("mail"),
Bpasswd: stmt.GetText("bpasswd"),
}
}

type StillerTemplateBlock struct {
Id int `json:"id"`
TemplateId int `json:"template"`
Expand All @@ -64,6 +79,16 @@ type StillerTemplate struct {
Description string `json:"description"`
}

func (st *StillerTemplate) FromStmt(stmt *sqlite.Stmt) {
*st = StillerTemplate{
Id: int(stmt.GetInt64("id")),
TierId: int(stmt.GetInt64("tier")),
TemplateId: int(stmt.GetInt64("templatefile")),
Title: stmt.GetText("title"),
Description: stmt.GetText("description"),
}
}

type StillerGallerySlot struct {
templates.MetatemplateSlot
RefId string `json:"ref"`
Expand Down

0 comments on commit e8c71d3

Please sign in to comment.