Skip to content

Commit

Permalink
Add new GetScript endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Nov 14, 2024
1 parent f012b7c commit 98c0a76
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions api/packages/getscript.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
cloudbox - the toybox server emulator
Copyright (C) 2024 patapancakes <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package packages

import (
"fmt"
"net/http"
"strconv"

"github.com/flatgrassdotnet/cloudbox/db"
"github.com/flatgrassdotnet/cloudbox/utils"
)

func GetScript(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(r.URL.Query().Get("id"))
if err != nil {
utils.WriteError(w, r, fmt.Sprintf("failed to parse id value: %s", err))
return
}

rev, _ := strconv.Atoi(r.URL.Query().Get("rev"))
if rev < 1 {
rev, err = db.FetchPackageLatestRevision(id)
if err != nil {
utils.WriteError(w, r, fmt.Sprintf("failed to fetch package latest revision: %s", err))
return
}
}

pkg, err := db.FetchPackage(id, rev)
if err != nil {
utils.WriteError(w, r, fmt.Sprintf("failed to fetch package: %s", err))
return
}

w.Write(pkg.Data)
}
1 change: 1 addition & 0 deletions cloudbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func main() {
http.HandleFunc("GET api.cl0udb0x.com/auth/getid", auth.GetID)
http.HandleFunc("GET api.cl0udb0x.com/packages/list", packages.List)
http.HandleFunc("GET api.cl0udb0x.com/packages/get", packages.Get)
http.HandleFunc("GET api.cl0udb0x.com/packages/getscript", packages.GetGMA)
http.HandleFunc("GET api.cl0udb0x.com/packages/getgma", packages.GetGMA)
http.HandleFunc("GET api.cl0udb0x.com/packages/publishsave", packages.PublishSave)
http.HandleFunc("GET api.cl0udb0x.com/content/get", content.Get)
Expand Down

0 comments on commit 98c0a76

Please sign in to comment.