Skip to content

Commit 0df0f93

Browse files
committed
fix: external printing api
1 parent 7aa7352 commit 0df0f93

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

frontend/src/js/app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ store.actions.loadAll().then(() => {
7575
'/workshop/:id': WorkshopSingle,
7676
'/workshop/:id/:repo': WorkshopRepo,
7777
'/extern-print/template/:id/:json/:config': ExternPrintTemplate,
78-
'/extern-print/generator/:id/:json/:config': ExternPrintGenerator,
78+
'/extern-print/generator/:id/:config': ExternPrintGenerator,
7979
});
8080

8181
document.addEventListener('keydown', (e) => {

frontend/src/js/types/entry.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ type Entry = {
22
id: string;
33
name: string;
44
data: Record<string, any>;
5+
source?: string;
56
};
67

78
export default Entry;

frontend/src/js/ui/views/extern-print/generator.ts

-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@ export default (): m.Component<ExternPrintProps> => {
2828
return {
2929
oninit({ attrs }) {
3030
state.id = attrs.id;
31-
state.json = JSON.parse(atob(attrs.json));
3231
state.gen = attrs.gen;
3332

34-
// TODO: is this right?
35-
3633
API.exec<Generator>(API.GET_GENERATOR, state.id)
3734
.then((gen) => {
3835
render(gen.printTemplate, {
39-
it: state.json,
4036
sources: gen.dataSources,
4137
images: gen.images,
4238
config: JSON.parse(atob(attrs.config)),

frontend/src/js/ui/views/template/create-entity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export default (): m.Component<CreateTemplateEntityProps> => {
173173
state.data = initialData(state.schema);
174174

175175
if (attrs.eid) {
176-
API.exec<Entry>(API.GET_ENTRY, attrs.id, attrs.eid)
176+
API.exec<Entry>(API.GET_ENTRY, attrs.id, atob(attrs.eid))
177177
.then((entry) => {
178178
state.data = entry.data;
179179
state.name = entry.name;

frontend/src/js/ui/views/template/single.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ export default (): m.Component<SingleTemplateProps> => {
230230
size: 'sm',
231231
icon: 'create',
232232
className: '.mr2',
233-
onClick: () => m.route.set(`/template/${buildId('template', state.template!)}/edit/${entry.id}`),
233+
disabled: entry.source?.startsWith('ds:'),
234+
onClick: () => m.route.set(`/template/${buildId('template', state.template!)}/edit/${btoa(entry.id)}`),
234235
}),
235236
),
236237
m(

rpc/print.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9-
"github.com/BigJk/snd/rpc/bind"
109
"image"
1110
"image/png"
1211
"io/ioutil"
@@ -18,6 +17,8 @@ import (
1817
"strings"
1918
"time"
2019

20+
"github.com/BigJk/snd/rpc/bind"
21+
2122
"github.com/BigJk/snd"
2223
"github.com/BigJk/snd/database"
2324
"github.com/patrickmn/go-cache"
@@ -286,27 +287,38 @@ func RegisterPrint(route *echo.Group, extern *echo.Group, db database.Database,
286287
return nil
287288
}
288289

289-
bind.MustBind(route, "/printTemplate", func(id string, entry snd.Entry, config interface{}) error {
290+
bind.MustBind(route, "/printTemplate", func(id string, entry snd.Entry, config map[string]any) error {
290291
_, err := db.GetTemplate(id)
291292
if err != nil {
292293
return err
293294
}
294295
return externPrintTemplate(id, entry, config)
295296
})
296297

297-
bind.MustBind(route, "/printTemplateEntry", func(id string, eid string, config interface{}) error {
298-
_, err := db.GetTemplate(id)
298+
bind.MustBind(route, "/printTemplateEntry", func(id string, eid string, config map[string]any) error {
299+
tmpl, err := db.GetTemplate(id)
299300
if err != nil {
300301
return err
301302
}
303+
302304
ent, err := db.GetEntry(id, eid)
303305
if err != nil {
306+
// Try to find the entry in the linked data sources
307+
for _, dsid := range tmpl.DataSources {
308+
if ds, err := db.GetSource(dsid); err == nil {
309+
if ent, err = db.GetEntry(ds.ID(), eid); err == nil {
310+
return externPrintTemplate(id, ent, config)
311+
}
312+
}
313+
}
314+
304315
return err
305316
}
317+
306318
return externPrintTemplate(id, ent, config)
307319
})
308320

309-
externPrintGenerator := func(genId string, config any) error {
321+
externPrintGenerator := func(genId string, config map[string]any) error {
310322
configJson, err := json.Marshal(config)
311323
if err != nil {
312324
return err
@@ -324,7 +336,7 @@ func RegisterPrint(route *echo.Group, extern *echo.Group, db database.Database,
324336
return nil
325337
}
326338

327-
bind.MustBind(route, "/printGenerator", func(id string, config interface{}) error {
339+
bind.MustBind(route, "/printGenerator", func(id string, config map[string]any) error {
328340
_, err := db.GetGenerator(id)
329341
if err != nil {
330342
return err

0 commit comments

Comments
 (0)