purgin git history cause accidentally upload vscode

This commit is contained in:
matu6968 2024-11-21 12:31:38 +01:00
commit 05a982ccb0
5 changed files with 239 additions and 0 deletions

16
LICENSE Normal file
View File

@ -0,0 +1,16 @@
Copyright 2024 matu6968
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

53
README.md Normal file
View File

@ -0,0 +1,53 @@
# WebDesk 3rd party App Market client
This allows you to interact with custom (known as 3rd party) App Market repositories of WebDesk applications.
## Features
- Listing currently uploaded apps
- Uploading new apps
- Editing app info
- Delete apps
## Prerequisites
- Go (1.23.1 or later, older will work with go.mod changes to the version)
## Installation
1. Clone the repository:
```
git clone https://git.fluffy.pw/matu6968/webdesk-app-market-client
```
2. Go to the project directory:
```
cd webdesk-app-market-client
```
3. Build the binary:
```
go build -o appmarketcli
```
4. Execture the binary:
```
./appmarketcli
```
# Configuration
In the .env file this is the only thing you can set
```
SERVER_URL=https://localhost:8080
AUTH_TOKEN=bearer-token-here # Grab token from .env file of the server
```
# How does this work
Command usage is explained in the program if you don't specify any command.
# !IMPORTANT!
You will need to set a token to interact with your server on anything outside of viewing apps in your .env file otherwaise actions like deleting apps will fail.

7
go.mod Normal file
View File

@ -0,0 +1,7 @@
module main.go
go 1.23.1
require github.com/joho/godotenv v1.5.1
require git.fluffy.pw/matu6968/webdesk-appmarket-golang v0.0.0-20241121111208-2d1dba808fe7 // indirect

4
go.sum Normal file
View File

@ -0,0 +1,4 @@
git.fluffy.pw/matu6968/webdesk-appmarket-golang v0.0.0-20241121111208-2d1dba808fe7 h1:VGAGfiT1pU02ANQtDP9NH2qTY3r5nXe524LLvPSdgjg=
git.fluffy.pw/matu6968/webdesk-appmarket-golang v0.0.0-20241121111208-2d1dba808fe7/go.mod h1:VfZZcLh2EA+3+O0AmCdiKWwmoBdr5J9U8leK+IAso9Q=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

159
main.go Normal file
View File

@ -0,0 +1,159 @@
package main
import (
"flag"
"fmt"
"log"
"os"
"git.fluffy.pw/matu6968/webdesk-appmarket-golang"
"github.com/joho/godotenv"
)
type Config struct {
ServerURL string
AuthToken string
}
func loadConfig() (*Config, error) {
if err := godotenv.Load(); err != nil {
return nil, fmt.Errorf("error loading .env file: %v", err)
}
serverURL := os.Getenv("SERVER_URL")
if serverURL == "" {
return nil, fmt.Errorf("SERVER_URL not set in .env file")
}
authToken := os.Getenv("AUTH_TOKEN")
if authToken == "" {
return nil, fmt.Errorf("AUTH_TOKEN not set in .env file")
}
return &Config{
ServerURL: serverURL,
AuthToken: authToken,
}, nil
}
func printUsage() {
fmt.Println("Usage:")
fmt.Println(" appmarketcli list - List all apps")
fmt.Println(" appmarketcli upload -name NAME -ver VER -info INFO -pub PUB [-appid `123456789011`] -file PATH - Upload new app")
fmt.Println(" appmarketcli edit -id APPID -name NAME -ver VER -info INFO -pub PUB [-file PATH] - Edit app")
fmt.Println(" appmarketcli delete -id APPID - Delete app")
}
func main() {
// Define command-line flags
listCmd := flag.NewFlagSet("list", flag.ExitOnError)
uploadCmd := flag.NewFlagSet("upload", flag.ExitOnError)
uploadName := uploadCmd.String("name", "", "App name")
uploadVer := uploadCmd.String("ver", "", "App version")
uploadInfo := uploadCmd.String("info", "", "App info")
uploadPub := uploadCmd.String("pub", "", "App publisher")
uploadFile := uploadCmd.String("file", "", "Path to app file")
uploadAppID := uploadCmd.String("appid", "", "Optional custom app ID")
editCmd := flag.NewFlagSet("edit", flag.ExitOnError)
editID := editCmd.String("id", "", "App ID")
editName := editCmd.String("name", "", "App name")
editVer := editCmd.String("ver", "", "App version")
editInfo := editCmd.String("info", "", "App info")
editPub := editCmd.String("pub", "", "App publisher")
editFile := editCmd.String("file", "", "Path to app file (optional)")
deleteCmd := flag.NewFlagSet("delete", flag.ExitOnError)
deleteID := deleteCmd.String("id", "", "App ID")
if len(os.Args) < 2 {
printUsage()
os.Exit(1)
}
// Load configuration
config, err := loadConfig()
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}
// Create client
c := client.NewClient(config.ServerURL, config.AuthToken)
// Parse commands
switch os.Args[1] {
case "list":
listCmd.Parse(os.Args[2:])
apps, err := c.GetApps()
if err != nil {
log.Fatalf("Failed to get apps: %v", err)
}
fmt.Println("Available apps:")
for _, app := range apps {
fmt.Printf("ID: %s\nName: %s\nVersion: %s\nInfo: %s\nPublisher: %s\nPath: %s\n\n",
app.AppID, app.Name, app.Ver, app.Info, app.Pub, app.Path)
}
case "upload":
uploadCmd.Parse(os.Args[2:])
if *uploadName == "" || *uploadVer == "" || *uploadInfo == "" || *uploadPub == "" || *uploadFile == "" {
fmt.Println("All fields are required for upload (except appid)")
uploadCmd.PrintDefaults()
os.Exit(1)
}
metadata := client.AppMetadata{
Name: *uploadName,
Ver: *uploadVer,
Info: *uploadInfo,
Pub: *uploadPub,
}
newApp, err := c.UploadApp(metadata, *uploadFile, *uploadAppID)
if err != nil {
log.Fatalf("Failed to upload app: %v", err)
}
fmt.Printf("Successfully uploaded app with ID: %s\n", newApp.AppID)
case "edit":
editCmd.Parse(os.Args[2:])
if *editID == "" || *editName == "" || *editVer == "" || *editInfo == "" || *editPub == "" {
fmt.Println("All fields except file are required for edit")
editCmd.PrintDefaults()
os.Exit(1)
}
metadata := client.AppMetadata{
Name: *editName,
Ver: *editVer,
Info: *editInfo,
Pub: *editPub,
}
err := c.EditApp(*editID, metadata, *editFile)
if err != nil {
log.Fatalf("Failed to edit app: %v", err)
}
fmt.Println("Successfully updated app")
case "delete":
deleteCmd.Parse(os.Args[2:])
if *deleteID == "" {
fmt.Println("App ID is required for delete")
deleteCmd.PrintDefaults()
os.Exit(1)
}
err := c.DeleteApp(*deleteID)
if err != nil {
log.Fatalf("Failed to delete app: %v", err)
}
fmt.Println("Successfully deleted app")
default:
printUsage()
os.Exit(1)
}
}