Update things to allow for shared links.

- fix non-looping loop to pull in new icons
- ghetto fix for timing issue on db creation
This commit is contained in:
Aaron Bieber 2022-12-21 19:23:44 -07:00
parent 728f9e1675
commit dc3dc81238
6 changed files with 87 additions and 53 deletions

View File

@ -2,6 +2,7 @@
<project version="4"> <project version="4">
<component name="SqlDialectMappings"> <component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/queries.sql" dialect="GenericSQL" /> <file url="file://$PROJECT_DIR$/queries.sql" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/schema.sql" dialect="SQLite" />
<file url="PROJECT" dialect="SQLite" /> <file url="PROJECT" dialect="SQLite" />
</component> </component>
</project> </project>

View File

@ -78,17 +78,19 @@ function deleteItem(path, id) {
} }
function sendLinkData() { function sendLinkData() {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var ln, lu, ll, data; var ln, lu, ll, ls, data;
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
ln = document.getElementById("linkname"); ln = document.getElementById("linkname");
lu = document.getElementById('linkurl'); lu = document.getElementById('linkurl');
ll = document.getElementById('logourl'); ll = document.getElementById('logourl');
ls = document.getElementById('linkshared');
data = {}; data = {};
data.Url = lu.value; data.Url = lu.value;
data.Name = ln.value; data.Name = ln.value;
data.Logo_Url = ll.value; data.Logo_Url = ll.value;
data.Shared = ls.checked;
return [4 /*yield*/, postData('/links', data)]; return [4 /*yield*/, postData('/links', data)];
case 1: case 1:
_a.sent(); _a.sent();

View File

@ -24,6 +24,7 @@ interface Link {
Url: string Url: string
Name: string Name: string
Clicked: number|null Clicked: number|null
Shared: boolean
Logo_Url: string Logo_Url: string
} }
@ -67,10 +68,12 @@ async function sendLinkData() {
const ln = document.getElementById("linkname") as HTMLInputElement; const ln = document.getElementById("linkname") as HTMLInputElement;
const lu = document.getElementById('linkurl') as HTMLInputElement; const lu = document.getElementById('linkurl') as HTMLInputElement;
const ll = document.getElementById('logourl') as HTMLInputElement; const ll = document.getElementById('logourl') as HTMLInputElement;
const ls = document.getElementById('linkshared') as HTMLInputElement;
let data = {} as Link; let data = {} as Link;
data.Url = lu.value; data.Url = lu.value;
data.Name = ln.value; data.Name = ln.value;
data.Logo_Url = ll.value; data.Logo_Url = ll.value;
data.Shared = ls.checked;
await postData('/links', data); await postData('/links', data);
} }
async function sendWatchData() { async function sendWatchData() {

20
main.go
View File

@ -59,8 +59,12 @@ func main() {
log.Fatal("can't get ts local client: ", err) log.Fatal("can't get ts local client: ", err)
} }
dbExists := false
if *dbFile == ":memory:" { if *dbFile == ":memory:" {
tmpDBPopulate(db) err := tmpDBPopulate(db)
if err != nil {
log.Fatal(err)
}
} else { } else {
if _, err := os.Stat(*dbFile); os.IsNotExist(err) { if _, err := os.Stat(*dbFile); os.IsNotExist(err) {
log.Println("Creating database..") log.Println("Creating database..")
@ -69,6 +73,10 @@ func main() {
} }
} }
} }
go func() {
time.Sleep(6 * time.Second)
dbExists = true
}()
if *key != "" { if *key != "" {
keyData, err := os.ReadFile(*key) keyData, err := os.ReadFile(*key)
@ -139,17 +147,23 @@ func main() {
go func() { go func() {
for { for {
if dbExists {
var err error var err error
app.watches, err = UpdateWatches(ghToken) app.watches, err = UpdateWatches(ghToken)
if err != nil { if err != nil {
log.Fatal("can't update watches: ", err) log.Fatal("can't update watches: ", err)
} }
time.Sleep(time.Duration(*watchInterval) * time.Minute) time.Sleep(time.Duration(*watchInterval) * time.Minute)
} else {
time.Sleep(3 * time.Second)
}
} }
}() }()
go func() { go func() {
if dbExists {
for {
links, err := app.queries.GetAllLinks(app.ctx) links, err := app.queries.GetAllLinks(app.ctx)
if err != nil { if err != nil {
log.Fatal("can't get links: ", err) log.Fatal("can't get links: ", err)
@ -190,6 +204,10 @@ func main() {
} }
} }
time.Sleep(24 * time.Hour) time.Sleep(24 * time.Hour)
}
} else {
time.Sleep(3 * time.Second)
}
}() }()
hs := &http.Server{ hs := &http.Server{

View File

@ -131,6 +131,10 @@
URL URL
<input id="linkurl" type="text" name="url" placeholder="https://..." required> <input id="linkurl" type="text" name="url" placeholder="https://..." required>
</label> </label>
<label for="shared">
Shared
<input id="linkshared" type="checkbox" required>
</label>
<label for="logourl"> <label for="logourl">
Logo URL Logo URL
<input id="logourl" type="text" name="logourl" placeholder="https://..." required> <input id="logourl" type="text" name="logourl" placeholder="https://..." required>

20
tmp.go
View File

@ -7,10 +7,10 @@ import (
"suah.dev/gostart/data" "suah.dev/gostart/data"
) )
func tmpDBPopulate(db *sql.DB) { func tmpDBPopulate(db *sql.DB) error {
log.Println("CREATING TEMP DATABASE!") log.Println("CREATING TEMP DATABASE!")
if _, err := db.ExecContext(app.ctx, schema); err != nil { if _, err := db.ExecContext(app.ctx, schema); err != nil {
log.Fatal("can't create schema in temp db: ", err) return err
} }
ownerID := int64(57395170551826799) ownerID := int64(57395170551826799)
@ -20,15 +20,18 @@ func tmpDBPopulate(db *sql.DB) {
Name: "europa.humpback-trout.ts.net.", Name: "europa.humpback-trout.ts.net.",
}) })
if err != nil { if err != nil {
log.Fatal("can't add temp owner: ", err) return err
} }
b, err := app.queries.AddLink(app.ctx, data.AddLinkParams{ _, err = app.queries.AddLink(app.ctx, data.AddLinkParams{
OwnerID: ownerID, OwnerID: ownerID,
Url: "https://tapenet.org", Url: "https://tapenet.org",
Name: "Tape::Net", Name: "Tape::Net",
Shared: true,
LogoUrl: "https://git.tapenet.org/assets/img/logo.svg", LogoUrl: "https://git.tapenet.org/assets/img/logo.svg",
}) })
log.Println(b, err) if err != nil {
return err
}
_, err = app.queries.AddPullRequest(app.ctx, data.AddPullRequestParams{ _, err = app.queries.AddPullRequest(app.ctx, data.AddPullRequestParams{
OwnerID: ownerID, OwnerID: ownerID,
@ -36,7 +39,7 @@ func tmpDBPopulate(db *sql.DB) {
Repo: "NixOS/nixpkgs", Repo: "NixOS/nixpkgs",
}) })
if err != nil { if err != nil {
log.Fatal("can't add temp PR: ", err) return err
} }
_, err = app.queries.AddWatchItem(app.ctx, data.AddWatchItemParams{ _, err = app.queries.AddWatchItem(app.ctx, data.AddWatchItemParams{
Name: "tailscale", Name: "tailscale",
@ -44,6 +47,9 @@ func tmpDBPopulate(db *sql.DB) {
OwnerID: ownerID, OwnerID: ownerID,
}) })
if err != nil { if err != nil {
log.Fatal("can't add temp watch item: ", err) return err
} }
log.Println("Done setting up tmp DB")
return nil
} }