Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
9 changed files with 4 additions and 120 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1 @@
|
||||||
debug.log
|
debug.log
|
||||||
/bin
|
|
||||||
|
|
|
||||||
23
README.md
23
README.md
|
|
@ -4,29 +4,6 @@ Quick tool to write gemtext posts for my gemlog.
|
||||||
|
|
||||||
=> gemini://travisshears.com/gemlog
|
=> gemini://travisshears.com/gemlog
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
Build and link. Remember to setup config file as well.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
$ go build -o bin/gemlog
|
|
||||||
$ ln -s /Users/xxxxxxxx/_projects/gemlog-cli/bin/gemlog-cli ~/bin/gemlog
|
|
||||||
```
|
|
||||||
|
|
||||||
## Config setup
|
|
||||||
|
|
||||||
This app relys on a config file at `~/.config/gemlog-cli/config.yml`
|
|
||||||
|
|
||||||
With the following format:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
couchdb:
|
|
||||||
host: http://myhost
|
|
||||||
port: 1234
|
|
||||||
user: gemlog-cli
|
|
||||||
password: xxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
||||||
```
|
|
||||||
|
|
||||||
## Dev
|
## Dev
|
||||||
|
|
||||||
To run command locally:
|
To run command locally:
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
meta {
|
|
||||||
name: Get Gemlog By Slug
|
|
||||||
type: http
|
|
||||||
seq: 6
|
|
||||||
}
|
|
||||||
|
|
||||||
get {
|
|
||||||
url: http://eisenhorn:5023/gemlog/_design/capsule/_view/post_by_slug?key="hello-from-gemlog-cli"
|
|
||||||
body: json
|
|
||||||
auth: basic
|
|
||||||
}
|
|
||||||
|
|
||||||
params:query {
|
|
||||||
key: "hello-from-gemlog-cli"
|
|
||||||
}
|
|
||||||
|
|
||||||
auth:basic {
|
|
||||||
username: gemlog-cli
|
|
||||||
password: {{pw}}
|
|
||||||
}
|
|
||||||
|
|
||||||
settings {
|
|
||||||
encodeUrl: true
|
|
||||||
}
|
|
||||||
5
build.sh
5
build.sh
|
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
go build -o ./bin/gemlog-cli
|
|
||||||
65
gemlog/db.go
65
gemlog/db.go
|
|
@ -17,7 +17,7 @@ func genBasicAuthHeader(user, password string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListGemLogs(config *Config) ([]GemlogListEntry, error) {
|
func ListGemLogs(config *Config) ([]GemlogListEntry, error) {
|
||||||
url := fmt.Sprintf("%s:%d/gemlog/_design/gemlog-cli/_view/list?descending=true", config.CouchDB.Host, config.CouchDB.Port)
|
url := fmt.Sprintf("%s:%d/gemlog/_design/gemlog-cli/_view/list", config.CouchDB.Host, config.CouchDB.Port)
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create request: %w", err)
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
||||||
|
|
@ -123,69 +123,6 @@ func ReadGemlogEntry(config *Config, id string) (GemlogEntry, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadGemlogEntryBySlug(config *Config, slug string) (GemlogEntry, error) {
|
|
||||||
url := fmt.Sprintf("%s:%d/gemlog/_design/capsule/_view/post_by_slug?key=\"%s\"", config.CouchDB.Host, config.CouchDB.Port, slug)
|
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return GemlogEntry{}, fmt.Errorf("failed to create request: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Add("authorization", genBasicAuthHeader(config.CouchDB.User, config.CouchDB.Password))
|
|
||||||
req.Header.Add("content-type", "application/json")
|
|
||||||
|
|
||||||
res, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return GemlogEntry{}, fmt.Errorf("failed to send request: %w", err)
|
|
||||||
}
|
|
||||||
defer res.Body.Close()
|
|
||||||
|
|
||||||
body, err := io.ReadAll(res.Body)
|
|
||||||
if err != nil {
|
|
||||||
return GemlogEntry{}, fmt.Errorf("failed to read response body: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
|
||||||
return GemlogEntry{}, fmt.Errorf("unexpected status code %d: %s", res.StatusCode, string(body))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode CouchDB view response
|
|
||||||
var viewResponse struct {
|
|
||||||
TotalRows int `json:"total_rows"`
|
|
||||||
Offset int `json:"offset"`
|
|
||||||
Rows []struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Key string `json:"key"`
|
|
||||||
Value struct {
|
|
||||||
ID string `json:"_id"`
|
|
||||||
Rev string `json:"_rev"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Slug string `json:"slug"`
|
|
||||||
Date time.Time `json:"date"`
|
|
||||||
Gemtxt string `json:"gemtxt"`
|
|
||||||
} `json:"value"`
|
|
||||||
} `json:"rows"`
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(body, &viewResponse); err != nil {
|
|
||||||
return GemlogEntry{}, fmt.Errorf("failed to parse response: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we got any results
|
|
||||||
if len(viewResponse.Rows) == 0 {
|
|
||||||
return GemlogEntry{}, fmt.Errorf("no document found with slug: %s", slug)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract the first (and should be only) result
|
|
||||||
doc := viewResponse.Rows[0].Value
|
|
||||||
|
|
||||||
return GemlogEntry{
|
|
||||||
Title: doc.Title,
|
|
||||||
Slug: doc.Slug,
|
|
||||||
Date: doc.Date,
|
|
||||||
Gemtxt: doc.Gemtxt,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeleteGemlogEntry(config *Config, id string, rev string) error {
|
func DeleteGemlogEntry(config *Config, id string, rev string) error {
|
||||||
url := fmt.Sprintf("%s:%d/gemlog/%s?rev=%s", config.CouchDB.Host, config.CouchDB.Port, id, rev)
|
url := fmt.Sprintf("%s:%d/gemlog/%s?rev=%s", config.CouchDB.Host, config.CouchDB.Port, id, rev)
|
||||||
req, err := http.NewRequest("DELETE", url, nil)
|
req, err := http.NewRequest("DELETE", url, nil)
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ func (m model) View() string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
var enableLogs bool = false
|
var enableLogs bool = true
|
||||||
|
|
||||||
func Run(config *gemlog.Config) {
|
func Run(config *gemlog.Config) {
|
||||||
if enableLogs {
|
if enableLogs {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func (m EntryListPageModel) Update(msg tea.Msg, active bool, ctx *context) (Entr
|
||||||
m.cursor--
|
m.cursor--
|
||||||
}
|
}
|
||||||
case "down", "j":
|
case "down", "j":
|
||||||
if m.cursor < len(m.entries)-1 {
|
if m.cursor < len(actions)-1 {
|
||||||
m.cursor++
|
m.cursor++
|
||||||
}
|
}
|
||||||
case "left", "h":
|
case "left", "h":
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
config "git.travisshears.com/travisshears/gemlog-cli/internal/config"
|
|
||||||
ui "git.travisshears.com/travisshears/gemlog-cli/internal/ui"
|
ui "git.travisshears.com/travisshears/gemlog-cli/internal/ui"
|
||||||
|
config "git.travisshears.com/travisshears/gemlog-cli/internal/ui/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue