Skip to content

Commit

Permalink
allow for missing snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
stackdump committed Jan 31, 2024
1 parent 9c26fe2 commit 4c00934
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 stackdump.com llc
Copyright (c) 2024 stackdump.com llc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 14 additions & 14 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BlobAccessor interface {
GetMaxId() int64
Create(ipfsCid, base64Zipped, title, description, keywords, referrer string) (int64, error)
}

type Storage struct {
Model BlobAccessor
Snippet BlobAccessor
Expand All @@ -38,6 +39,7 @@ type Service interface {
CheckForSnippet(hostname string, url string, referrer string) (string, bool)
CheckForModel(hostname string, url string, referrer string) (string, bool)
}

type App struct {
Service
Storage
Expand Down Expand Up @@ -113,20 +115,18 @@ func (app *App) SandboxHandler(vars map[string]string, w http.ResponseWriter, r
cid, found := app.CheckForSnippet(r.Host, r.URL.String(), r.Header.Get("Referer"))
if found {
http.Redirect(w, r, "/sandbox/"+cid+"/", http.StatusFound)
} else if vars["pflowCid"] != "" {
return
}
templateData := struct {
IpfsCid string
SourceCode string
}{
IpfsCid: vars["pflowCid"],
SourceCode: "",
}
if vars["pflowCid"] != "" {
rec := app.Storage.Snippet.GetByCid(vars["pflowCid"])
sourceCode, ok := metamodel.UnzipUrl("?z="+rec.Base64Zipped, "declaration.js")
if !ok {
http.Error(w, "Failed to unzip snippet", http.StatusInternalServerError)
return
}
templateData := struct {
IpfsCid string
SourceCode string
}{
IpfsCid: vars["pflowCid"],
SourceCode: sourceCode,
}
app.SandboxPage().ExecuteTemplate(w, "sandbox.html", templateData)
templateData.SourceCode, _ = metamodel.UnzipUrl("?z="+rec.Base64Zipped, "declaration.js")
}
app.SandboxPage().ExecuteTemplate(w, "sandbox.html", templateData)
}

0 comments on commit 4c00934

Please sign in to comment.