-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* various fixes, added explore page * Edit schematics, delete schematics, delete account and more
- Loading branch information
Showing
48 changed files
with
1,438 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ | |
pb_data | ||
migration_data | ||
main | ||
dbdata | ||
template | ||
dbdata |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package models | ||
|
||
type ImageData struct { | ||
ID string | ||
Name string | ||
Title string | ||
Image string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package pages | ||
|
||
import ( | ||
"createmod/internal/cache" | ||
"createmod/internal/models" | ||
"createmod/internal/search" | ||
"fmt" | ||
"github.com/pocketbase/dbx" | ||
"github.com/pocketbase/pocketbase" | ||
"github.com/pocketbase/pocketbase/core" | ||
template2 "github.com/pocketbase/pocketbase/tools/template" | ||
"net/http" | ||
) | ||
|
||
var editSchematicTemplates = []string{ | ||
"./template/dist/editschematic.html", | ||
} | ||
|
||
type EditSchematicData struct { | ||
DefaultData | ||
Schematic models.Schematic | ||
AuthorHasMore bool | ||
// IsAuthor of the current schematic, for edit and delete actions | ||
IsAuthor bool | ||
MinecraftVersions []models.MinecraftVersion | ||
CreatemodVersions []models.CreatemodVersion | ||
Tags []models.SchematicTag | ||
TagsWithSelected []SchematicTagWithSelected | ||
CreateModVersionId string | ||
} | ||
|
||
type SchematicTagWithSelected struct { | ||
models.SchematicTag | ||
Selected bool | ||
} | ||
|
||
func EditSchematicHandler(app *pocketbase.PocketBase, searchService *search.Service, cacheService *cache.Service, registry *template2.Registry) func(e *core.RequestEvent) error { | ||
return func(e *core.RequestEvent) error { | ||
schematicsCollection, err := app.FindCollectionByNameOrId("schematics") | ||
if err != nil { | ||
return err | ||
} | ||
results, err := app.FindRecordsByFilter( | ||
schematicsCollection.Id, | ||
"name = {:name}", | ||
"-created", | ||
1, | ||
0, | ||
dbx.Params{"name": e.Request.PathValue("name")}) | ||
|
||
if len(results) != 1 { | ||
html, err := registry.LoadFiles(fourOhFourTemplate).Render(nil) | ||
if err != nil { | ||
return err | ||
} | ||
return e.HTML(http.StatusNotFound, html) | ||
} | ||
|
||
d := EditSchematicData{ | ||
Schematic: mapResultToSchematic(app, results[0], cacheService), | ||
} | ||
d.Populate(e) | ||
d.Title = fmt.Sprintf("Editing %s", d.Schematic.Title) | ||
d.Slug = fmt.Sprintf("schematics/%s/edit", d.Schematic.Name) | ||
d.Description = d.Schematic.Content | ||
d.Thumbnail = fmt.Sprintf("https://createmod.com/api/files/schematics/%s/%s", d.Schematic.ID, d.Schematic.FeaturedImage) | ||
d.SubCategory = "Schematic" | ||
d.Categories = allCategories(app, cacheService) | ||
d.Tags = allTags(app) | ||
d.MinecraftVersions = allMinecraftVersions(app) | ||
d.CreatemodVersions = allCreatemodVersions(app) | ||
d.IsAuthor = d.Schematic.Author.ID == d.UserID | ||
d.CreateModVersionId = results[0].GetString("createmod_version") | ||
|
||
for _, t := range d.Tags { | ||
selected := false | ||
for _, t2 := range d.Schematic.Tags { | ||
if t.Key == t2.Key { | ||
selected = true | ||
} | ||
} | ||
d.TagsWithSelected = append(d.TagsWithSelected, SchematicTagWithSelected{ | ||
SchematicTag: t, | ||
Selected: selected, | ||
}) | ||
} | ||
|
||
countSchematicView(app, results[0]) | ||
html, err := registry.LoadFiles(editSchematicTemplates...).Render(d) | ||
if err != nil { | ||
return err | ||
} | ||
return e.HTML(http.StatusOK, html) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package pages | ||
|
||
import ( | ||
"createmod/internal/cache" | ||
"createmod/internal/models" | ||
"fmt" | ||
"github.com/pocketbase/dbx" | ||
"github.com/pocketbase/pocketbase" | ||
"github.com/pocketbase/pocketbase/core" | ||
"github.com/pocketbase/pocketbase/tools/template" | ||
"math/rand/v2" | ||
"net/http" | ||
) | ||
|
||
var exploreTemplates = []string{ | ||
"./template/dist/explore.html", | ||
} | ||
|
||
type ExploreData struct { | ||
DefaultData | ||
Images []models.ImageData | ||
} | ||
|
||
func ExploreHandler(app *pocketbase.PocketBase, cacheService *cache.Service, registry *template.Registry) func(e *core.RequestEvent) error { | ||
return func(e *core.RequestEvent) error { | ||
schematicsCollection, err := app.FindCollectionByNameOrId("schematics") | ||
if err != nil { | ||
return err | ||
} | ||
var results []core.Record | ||
err = app.RecordQuery(schematicsCollection).Select("id", "name", "title", "featured_image", "gallery").Where(dbx.NewExp("deleted = null")).All(&results) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
images := make([]models.ImageData, 0) | ||
for _, result := range results { | ||
for _, g := range result.GetStringSlice("gallery") { | ||
images = append(images, models.ImageData{ | ||
ID: result.Id, | ||
Title: result.GetString("title"), | ||
Name: result.GetString("name"), | ||
Image: g, | ||
}) | ||
} | ||
images = append(images, models.ImageData{ | ||
ID: result.Id, | ||
Title: result.GetString("title"), | ||
Name: result.GetString("name"), | ||
Image: result.GetString("featured_image"), | ||
}) | ||
} | ||
|
||
show := len(images) | ||
if show > 1000 { | ||
show = 1000 | ||
} | ||
dest := make([]models.ImageData, show) | ||
perm := rand.Perm(show) | ||
for i, v := range perm { | ||
dest[v] = images[i] | ||
} | ||
|
||
d := ExploreData{ | ||
Images: dest, | ||
} | ||
d.Populate(e) | ||
d.Title = "Explore Create Mod Schematics" | ||
d.Categories = allCategories(app, cacheService) | ||
d.Description = "Explore a random gallery of Create Mod schematics" | ||
d.Slug = "/explore" | ||
if len(dest) > 0 { | ||
d.Thumbnail = fmt.Sprintf("https://createmod.com/api/files/schematics/%s/%s", dest[0].ID, dest[0].Image) | ||
} | ||
html, err := registry.LoadFiles(exploreTemplates...).Render(d) | ||
if err != nil { | ||
return err | ||
} | ||
return e.HTML(http.StatusOK, html) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.