Compare commits

..

No commits in common. "fe98112f796d39bb14175386f6e0a0b29e94500b" and "e13252d36826004f298a96c2ed4bb8e9df4ea61c" have entirely different histories.

3 changed files with 8 additions and 36 deletions

View File

@ -20,14 +20,13 @@ fn read_repos(path string) ?[]GitRepo {
f.close() f.close()
} }
f.write_string('[]') ? f.write_string('{}') ?
return [] return []
} }
content := os.read_file(path) ? content := os.read_file(path) ?
res := json.decode([]GitRepo, content) ? return json.decode([]GitRepo, content)
return res
} }
fn write_repos(path string, repos []GitRepo) ? { fn write_repos(path string, repos []GitRepo) ? {
@ -37,6 +36,7 @@ fn write_repos(path string, repos []GitRepo) ? {
f.close() f.close()
} }
dump(repos)
value := json.encode(repos) value := json.encode(repos)
f.write_string(value) ? f.write_string(value) ?
} }
@ -91,39 +91,10 @@ pub fn (mut app App) post_repo() web.Result {
repos << new_repo repos << new_repo
lock app.git_mutex { lock app.git_mutex {
write_repos(app.conf.repos_file, repos) or { return app.server_error(500) } write_repos(app.conf.repos_file, repos) or {
return app.server_error(500)
}
} }
return app.ok('Repo added successfully.') return app.ok('Repo added successfully.')
} }
['/api/repos'; delete]
pub fn (mut app App) delete_repo() web.Result {
if !app.is_authorized() {
return app.text('Unauthorized.')
}
if !('url' in app.query && 'branch' in app.query) {
return app.server_error(400)
}
repo_to_remove := GitRepo{
url: app.query['url']
branch: app.query['branch']
}
mut repos := rlock app.git_mutex {
read_repos(app.conf.repos_file) or {
app.lerror('Failed to read repos file.')
return app.server_error(500)
}
}
filtered := repos.filter(it != repo_to_remove)
lock app.git_mutex {
write_repos(app.conf.repos_file, filtered) or { return app.server_error(500) }
}
return app.ok('Repo removed successfully.')
}

View File

@ -88,3 +88,4 @@ pub fn pretty_bytes(bytes int) string {
return '${n:.2}${util.prefixes[i]}' return '${n:.2}${util.prefixes[i]}'
} }