Skip to content

Commit

Permalink
update to router methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Jul 12, 2024
1 parent 03c8ed9 commit 50d9d36
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 134 deletions.
2 changes: 1 addition & 1 deletion assets/js/uploader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function checkSHA(file) {
try {
const hash = await sha384(file);
const response = await fetch(`/uploader/sha384/${hash}`, {
method: "PUT",
method: "PATCH",
headers: {
"Content-Type": "text/plain",
},
Expand Down
4 changes: 1 addition & 3 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
### Emulate on startup fixes

- [ ] On dosee_hardware_cpu, machine, sound etc set "auto" and all other invalid strings to "" (empty).
- [ ] Load GUS drivers for the emulator.
- [ ] Delete emulate no aspect ratio from the database, as it isn't used.
- [ ] Repack zips that contain programs with bad filenames, for example: http://localhost:1323/f/ab252e4
- [ ] Create a UTILS zip archive to hold drivers and libraries for the emulator.
- [ ] Replace PUT with POST/PATCH except for the artifact file upload.
- [ ] Create a DRIVER.ZIP archive to load in js-dos, it should contain GUS drivers and DOS4GW.EXE etc.

### Templates

Expand Down
4 changes: 2 additions & 2 deletions handler/app/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func recordLastMod(b bool) template.HTML {
}

func radioPublic(b bool) template.HTML {
const htmx = ` hx-post="/editor/online/true"
const htmx = ` hx-patch="/editor/online/true"
hx-include="[name='artifact-editor-key']"`
if b {
return template.HTML(radio +
Expand All @@ -316,7 +316,7 @@ func radioPublic(b bool) template.HTML {
}

func radioHidden(b bool) template.HTML {
const htmx = ` hx-post="/editor/online/false"
const htmx = ` hx-patch="/editor/online/false"
hx-include="[name='artifact-editor-key']"`
if !b {
return template.HTML(radio +
Expand Down
8 changes: 4 additions & 4 deletions handler/htmx/htmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func DemozooProd(c echo.Context) error {
}
html := `<div class="d-grid gap-2">`
html += fmt.Sprintf(`<button type="button" class="btn btn-outline-success" `+
`hx-post="/demozoo/production/submit/%d" `+
`hx-put="/demozoo/production/%d" `+
`hx-target="#demozoo-submission-results" hx-trigger="click once delay:500ms" `+
`autofocus>Submit ID %d</button>`, id, id)
html += `</div>`
Expand Down Expand Up @@ -138,7 +138,7 @@ func DemozooValid(c echo.Context, id int) (demozoo.Production, error) {
return prod, nil
}

// DemozooSubmit is the handler for the /demozoo/production/submit route.
// DemozooSubmit is the handler for the /demozoo/production put route.
// This will attempt to insert a new file record into the database using
// the Demozoo production ID. If the Demozoo production ID is already in
// use, an error message is returned.
Expand Down Expand Up @@ -356,7 +356,7 @@ func PouetProd(c echo.Context) error {
func htmler(id int, info ...string) string {
s := `<div class="d-grid gap-2">`
s += fmt.Sprintf(`<button type="button" class="btn btn-outline-success" `+
`hx-post="/pouet/production/submit/%d" hx-target="#pouet-submission-results" hx-trigger="click once delay:500ms" `+
`hx-put="/pouet/production/%d" hx-target="#pouet-submission-results" hx-trigger="click once delay:500ms" `+
`autofocus>Submit ID %d</button>`, id, id)
s += `</div>`
s += fmt.Sprintf(`<p class="mt-3">%s</p>`, strings.Join(info, " "))
Expand Down Expand Up @@ -417,7 +417,7 @@ func PouetValid(c echo.Context, id int) (pouet.Response, error) {
return prod, nil
}

// PouetSubmit is the handler for the /pouet/production/submit route.
// PouetSubmit is the handler for the /pouet/production PUT route.
// This will attempt to insert a new file record into the database using
// the Pouet production ID. If the Pouet production ID is already in
// use, an error message is returned.
Expand Down
2 changes: 1 addition & 1 deletion handler/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (c Configuration) NoCrawl(next echo.HandlerFunc) echo.HandlerFunc {
}
}

// ReadOnlyLock disables all POST, PUT and DELETE requests for the modification
// ReadOnlyLock disables all PATCH, POST, PUT and DELETE requests for the modification
// of the database and any related user interface.
func (c Configuration) ReadOnlyLock(next echo.HandlerFunc) echo.HandlerFunc {
return func(e echo.Context) error {
Expand Down
59 changes: 32 additions & 27 deletions handler/routerhtmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,54 @@ func htmxGroup(e *echo.Echo, logger *zap.SugaredLogger, downloadDir string) *ech
}
store := middleware.NewRateLimiterMemoryStore(rateLimit)
g := e.Group("", middleware.RateLimiter(store))
g.PUT("/uploader/sha384/:hash", func(c echo.Context) error {
return htmx.LookupSHA384(c, logger)
g.PATCH("/search/releaser", func(c echo.Context) error {
return htmx.SearchReleaser(c, logger)
})
g.POST("/demozoo/production", htmx.DemozooProd)
g.POST("/demozoo/production/submit/:id", func(c echo.Context) error {

demozoo := g.Group("/demozoo")
demozoo.GET("/production", htmx.DemozooProd)
demozoo.PUT("/production/:id", func(c echo.Context) error {
return htmx.DemozooSubmit(c, logger)
})
g.POST("/pouet/production", htmx.PouetProd)
g.POST("/pouet/production/submit/:id", func(c echo.Context) error {
pouet := g.Group("/pouet")
pouet.GET("/production", htmx.PouetProd)
pouet.PUT("/production/:id", func(c echo.Context) error {
return htmx.PouetSubmit(c, logger)
})
g.POST("/search/releaser", func(c echo.Context) error {
return htmx.SearchReleaser(c, logger)
})
g.POST("/uploader/advanced", func(c echo.Context) error {
return htmx.AdvancedSubmit(c, logger, downloadDir)
})
g.POST("/uploader/classifications", func(c echo.Context) error {

upload := g.Group("/uploader")
upload.GET("/classifications", func(c echo.Context) error {
return htmx.HumanizeAndCount(c, logger, "uploader-advanced")
})
g.POST("/uploader/image", func(c echo.Context) error {
return htmx.ImageSubmit(c, logger, downloadDir)
})
g.POST("/uploader/intro", func(c echo.Context) error {
return htmx.IntroSubmit(c, logger, downloadDir)
})
g.POST("/uploader/magazine", func(c echo.Context) error {
return htmx.MagazineSubmit(c, logger, downloadDir)
})
g.POST("/uploader/releaser/1", func(c echo.Context) error {
upload.PATCH("/releaser/1", func(c echo.Context) error {
return htmx.DataListReleasers(c, logger, releaser1(c))
})
g.POST("/uploader/releaser/2", func(c echo.Context) error {
upload.PATCH("/releaser/2", func(c echo.Context) error {
return htmx.DataListReleasers(c, logger, releaser2(c))
})
g.POST("/uploader/releaser/magazine", func(c echo.Context) error {
upload.PATCH("/releaser/magazine", func(c echo.Context) error {
lookup := c.FormValue("uploader-magazine-releaser1")
return htmx.DataListMagazines(c, logger, lookup)
})
g.POST("/uploader/text", func(c echo.Context) error {
upload.PATCH("/sha384/:hash", func(c echo.Context) error {
return htmx.LookupSHA384(c, logger)
})
upload.POST("/advanced", func(c echo.Context) error {
return htmx.AdvancedSubmit(c, logger, downloadDir)
})
upload.POST("/image", func(c echo.Context) error {
return htmx.ImageSubmit(c, logger, downloadDir)
})
upload.POST("/intro", func(c echo.Context) error {
return htmx.IntroSubmit(c, logger, downloadDir)
})
upload.POST("/magazine", func(c echo.Context) error {
return htmx.MagazineSubmit(c, logger, downloadDir)
})
upload.POST("/text", func(c echo.Context) error {
return htmx.TextSubmit(c, logger, downloadDir)
})
g.POST("/uploader/trainer", func(c echo.Context) error {
upload.POST("/trainer", func(c echo.Context) error {
return htmx.TrainerSubmit(c, logger, downloadDir)
})
return e
Expand Down
73 changes: 35 additions & 38 deletions handler/routerlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
// that are locked behind the router middleware and require a user to be logged in.

/*
A note about the used request methods:
A note about the request methods in use:
- GET requests are used for retrieving data from the server.
- PATCH requests are used for updating data on the server.
- PATCH requests are used for updating or retrieving data on the server.
- PUT requests are used for creating new data on the server.
- POST requests are used for uploading files with or without data.
- DELETE requests are used for removing data from the server.
Expand Down Expand Up @@ -64,23 +64,23 @@ func creator(g *echo.Group) {
panic(ErrRoutes)
}
creator := g.Group("/creator")
creator.POST("/text", htmx.RecordCreatorText)
creator.POST("/ill", htmx.RecordCreatorIll)
creator.POST("/prog", htmx.RecordCreatorProg)
creator.POST("/audio", htmx.RecordCreatorAudio)
creator.POST("/reset", htmx.RecordCreatorReset)
creator.PATCH("/text", htmx.RecordCreatorText)
creator.PATCH("/ill", htmx.RecordCreatorIll)
creator.PATCH("/prog", htmx.RecordCreatorProg)
creator.PATCH("/audio", htmx.RecordCreatorAudio)
creator.PATCH("/reset", htmx.RecordCreatorReset)
}

func date(g *echo.Group) {
if g == nil {
panic(fmt.Errorf("%w for date router", ErrRoutes))
}
date := g.Group("/date")
date.POST("", htmx.RecordDateIssued)
date.POST("/reset", func(cx echo.Context) error {
date.PATCH("", htmx.RecordDateIssued)
date.PATCH("/reset", func(cx echo.Context) error {
return htmx.RecordDateIssuedReset(cx, "artifact-editor-date-resetter")
})
date.POST("/lastmod", func(cx echo.Context) error {
date.PATCH("/lastmod", func(cx echo.Context) error {
return htmx.RecordDateIssuedReset(cx, "artifact-editor-date-lastmodder")
})
}
Expand All @@ -93,35 +93,35 @@ func editor(g *echo.Group, logger *zap.SugaredLogger, dir app.Dirs) {
return htmx.DeleteForever(c, logger, c.Param("key"))
})

g.POST("/16colors", htmx.Record16Colors)
g.PATCH("/16colors", htmx.Record16Colors)
g.POST("/ansilove/copy", func(c echo.Context) error {
return dir.AnsiLovePost(c, logger)
})
g.POST("/classifications", func(c echo.Context) error {
g.PATCH("/classifications", func(c echo.Context) error {
return htmx.RecordClassification(c, logger)
})
g.PATCH("/comment", htmx.RecordComment)
g.PATCH("/comment/reset", htmx.RecordCommentReset)
g.POST("/demozoo", htmx.RecordDemozoo)
g.POST("/filename", htmx.RecordFilename)
g.POST("/filename/reset", htmx.RecordFilenameReset)
g.POST("/github", htmx.RecordGitHub)
g.POST("/links", htmx.RecordLinks)
g.POST("/links/reset", htmx.RecordLinksReset)
g.POST("/platform", app.PlatformEdit)
g.POST("/platform+tag", app.PlatformTagInfo)
g.POST("/pouet", htmx.RecordPouet)
g.POST("/relations", htmx.RecordRelations)
g.POST("/releasers", htmx.RecordReleasers)
g.POST("/releasers/reset", htmx.RecordReleasersReset)
g.POST("/sites", htmx.RecordSites)
g.POST("/tag", app.TagEdit)
g.POST("/tag/info", app.TagInfo)
g.POST("/title", htmx.RecordTitle)
g.POST("/title/reset", htmx.RecordTitleReset)
g.POST("/virustotal", htmx.RecordVirusTotal)
g.POST("/ymd", app.YMDEdit)
g.POST("/youtube", htmx.RecordYouTube)
g.PATCH("/demozoo", htmx.RecordDemozoo)
g.PATCH("/filename", htmx.RecordFilename)
g.PATCH("/filename/reset", htmx.RecordFilenameReset)
g.PATCH("/github", htmx.RecordGitHub)
g.PATCH("/links", htmx.RecordLinks)
g.PATCH("/links/reset", htmx.RecordLinksReset)
g.PATCH("/platform", app.PlatformEdit)
g.PATCH("/platform+tag", app.PlatformTagInfo)
g.PATCH("/pouet", htmx.RecordPouet)
g.PATCH("/relations", htmx.RecordRelations)
g.PATCH("/releasers", htmx.RecordReleasers)
g.PATCH("/releasers/reset", htmx.RecordReleasersReset)
g.PATCH("/sites", htmx.RecordSites)
g.PATCH("/tag", app.TagEdit)
g.PATCH("/tag/info", app.TagInfo)
g.PATCH("/title", htmx.RecordTitle)
g.PATCH("/title/reset", htmx.RecordTitleReset)
g.PATCH("/virustotal", htmx.RecordVirusTotal)
g.PATCH("/ymd", app.YMDEdit)
g.PATCH("/youtube", htmx.RecordYouTube)

emu := g.Group("/emulate")
emu.PATCH("/broken/:id", htmx.RecordEmulateBroken)
Expand Down Expand Up @@ -172,10 +172,10 @@ func online(g *echo.Group) {
panic(fmt.Errorf("%w for online router", ErrRoutes))
}
online := g.Group("/online")
online.POST("/true", func(cx echo.Context) error {
online.PATCH("/true", func(cx echo.Context) error {
return htmx.RecordToggle(cx, true)
})
online.POST("/false", func(cx echo.Context) error {
online.PATCH("/false", func(cx echo.Context) error {
return htmx.RecordToggle(cx, false)
})
online.GET("/true/:id", func(cx echo.Context) error {
Expand All @@ -189,12 +189,9 @@ func search(g *echo.Group, logger *zap.SugaredLogger) {
}
search := g.Group("/search")
search.GET("/id", app.SearchID)
search.POST("/id", func(cx echo.Context) error {
search.PATCH("/id", func(cx echo.Context) error {
return htmx.SearchByID(cx, logger)
})
// search.POST("/reset", func(cx echo.Context) error {
// return htmx.RecordSearchReset(cx)
// })
}

func readme(g *echo.Group, logger *zap.SugaredLogger, dir app.Dirs) {
Expand Down
2 changes: 1 addition & 1 deletion public/js/uploader.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 50d9d36

Please sign in to comment.