This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip heroweb test macos error on linux
- Loading branch information
1 parent
680d780
commit 3e6a58b
Showing
25 changed files
with
535 additions
and
213 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
module heroweb | ||
|
||
import veb | ||
import freeflowuniverse.crystallib.core.pathlib | ||
import freeflowuniverse.crystallib.webserver.log | ||
import time | ||
|
||
@['/assets'] | ||
pub fn (mut app App) assets(mut ctx Context) veb.Result { | ||
ptrs := app.db.authorized_ptrs(ctx.user_id, .read) or { | ||
return ctx.server_error(err.str()) | ||
} | ||
docs := ptrs.map(Document{ | ||
title: it.name.title() | ||
description: it.description | ||
url: '/view/asset/${it.name}' | ||
}) | ||
|
||
return ctx.json(docs) | ||
} | ||
|
||
// this endpoint serves assets dynamically | ||
@['/asset/:paths...'] | ||
pub fn (app &App) asset(mut ctx Context, paths string) veb.Result { | ||
name := paths.all_before('/') | ||
infoptr := app.db.infopointers[name] or { | ||
return ctx.not_found() | ||
} | ||
|
||
mut path := pathlib.get('${infoptr.path_content}${paths.all_after(name)}') | ||
println('debugzopath ${path}') | ||
|
||
logger := log.new('logger.sqlite') or { | ||
return ctx.server_error(err.str()) | ||
} | ||
// if infoptr.cat == .website && ctx.req.url.ends_with('.html') { | ||
// logger.new_log(log.Log{ | ||
// object: infoptr.name | ||
// timestamp: time.now() | ||
// subject: ctx.user_id.str() | ||
// message: 'access path ${ctx.req.url}' | ||
// event: 'view' | ||
// }) or { | ||
// return ctx.server_error(err.str()) | ||
// } | ||
// } | ||
// println('debugzopath ${infoptr}') | ||
|
||
file := if path.is_file() { | ||
path | ||
} else { | ||
// mount the folder 'static' at path '/public', the path has to start with '/' | ||
pathlib.get_file(path: '${path.path}/index.html') or { | ||
return ctx.server_error(err.str()) | ||
} | ||
} | ||
println('debugzopath2 ${file}') | ||
|
||
// ctx.set_content_type('application/pdf') | ||
return ctx.file(file.path) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module heroweb | ||
|
||
import json | ||
import veb | ||
import time | ||
import freeflowuniverse.crystallib.core.pathlib | ||
import freeflowuniverse.crystallib.webserver.log | ||
|
||
@[POST; '/log/:name'] | ||
pub fn (mut app App) log_post(mut ctx Context, name string) veb.Result { | ||
infoptr := app.db.infopointers[name] or { | ||
return ctx.not_found() | ||
} | ||
|
||
// new_log := json.decode(log.Log, ctx.req.data) or { | ||
// return ctx.server_error(err.str()) | ||
// } | ||
// app.db.new_log(log.Log{...new_log, | ||
// subject: ctx.user_id.str() | ||
// timestamp: time.now() | ||
// }) or { | ||
// return ctx.server_error(err.str()) | ||
// } | ||
|
||
return ctx.json('ok') | ||
} | ||
|
||
@[GET; '/logs'] | ||
pub fn (mut app App) logs(mut ctx Context) veb.Result { | ||
// logs := app.db.filter_logs( | ||
// event: ctx.query['event'] or { '' } | ||
// subject: ctx.query['subject'] or { '' } | ||
// object: ctx.query['object'] or { '' } | ||
// ) or { | ||
// return ctx.server_error(err.str()) | ||
// } | ||
|
||
return ctx.json('logs') | ||
} |
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
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.