Update upload page
This commit is contained in:
parent
06fbe78dca
commit
32c89bc12c
9 changed files with 166 additions and 37 deletions
|
|
@ -131,27 +131,52 @@ pub const Song = jetquery.Model(
|
|||
},
|
||||
);
|
||||
|
||||
pub const Alias = jetquery.Model(@This(), "aliases", struct {
|
||||
id: i32,
|
||||
reference_id: i32,
|
||||
alias: []const u8,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
}, .{});
|
||||
pub const Alias = jetquery.Model(
|
||||
@This(),
|
||||
"aliases",
|
||||
struct {
|
||||
id: i32,
|
||||
reference_id: i32,
|
||||
alias: []const u8,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
},
|
||||
.{},
|
||||
);
|
||||
|
||||
pub const Concert = jetquery.Model(@This(), "concerts", struct {
|
||||
id: i32,
|
||||
location: []const u8,
|
||||
date: jetquery.DateTime,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
}, .{});
|
||||
pub const Concert = jetquery.Model(
|
||||
@This(),
|
||||
"concerts",
|
||||
struct {
|
||||
id: i32,
|
||||
location: []const u8,
|
||||
date: jetquery.DateTime,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
},
|
||||
.{},
|
||||
);
|
||||
|
||||
pub const Rating = jetquery.Model(@This(), "ratings", struct {
|
||||
pub const Rating = jetquery.Model(
|
||||
@This(),
|
||||
"ratings",
|
||||
struct {
|
||||
id: i32,
|
||||
reference_id: i32,
|
||||
score: f64,
|
||||
date: jetquery.DateTime,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
},
|
||||
.{},
|
||||
);
|
||||
|
||||
pub const RawScrobble = jetquery.Model(@This(), "raw_scrobbles", struct {
|
||||
id: i32,
|
||||
reference_id: i32,
|
||||
score: f64,
|
||||
date: jetquery.DateTime,
|
||||
track: []const u8,
|
||||
artist: []const u8,
|
||||
album: []const u8,
|
||||
date: i32,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
}, .{});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
const std = @import("std");
|
||||
const jetquery = @import("jetquery");
|
||||
const t = jetquery.schema.table;
|
||||
|
||||
pub fn up(repo: anytype) !void {
|
||||
try repo.createTable(
|
||||
"raw_scrobbles",
|
||||
&.{
|
||||
t.primaryKey("id", .{}),
|
||||
t.column("track", .string, .{}),
|
||||
t.column("artist", .string, .{}),
|
||||
t.column("album", .string, .{}),
|
||||
t.column("date", .integer, .{}),
|
||||
t.timestamps(.{}),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn down(repo: anytype) !void {
|
||||
try repo.dropTable("raw_scrobbles", .{});
|
||||
}
|
||||
18
src/app/jobs/process_scrobbles.zig
Normal file
18
src/app/jobs/process_scrobbles.zig
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
const std = @import("std");
|
||||
const jetzig = @import("jetzig");
|
||||
|
||||
// The `run` function for a job is invoked every time the job is processed by a queue worker
|
||||
// (or by the Jetzig server if the job is processed in-line).
|
||||
//
|
||||
// Arguments:
|
||||
// * allocator: Arena allocator for use during the job execution process.
|
||||
// * params: Params assigned to a job (from a request, any values added to `data`).
|
||||
// * env: Provides the following fields:
|
||||
// - logger: Logger attached to the same stream as the Jetzig server.
|
||||
// - environment: Enum of `{ production, development }`.
|
||||
pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig.jobs.JobEnv) !void {
|
||||
_ = allocator;
|
||||
_ = params;
|
||||
// Job execution code goes here. Add any code that you would like to run in the background.
|
||||
try env.logger.INFO("Running a job.", .{});
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
@args table_data: *ZmplValue, table_headers: *ZmplValue
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
@for (table_headers) |text| {
|
||||
<th>{{text}}</th>
|
||||
}
|
||||
</tr>
|
||||
|
||||
@for (table_data) |value| {
|
||||
<tr>
|
||||
<td class=cell>{{value.track}}</td>
|
||||
<td class=cell>{{value.artist}}</td>
|
||||
<td class=cell>{{value.album}}</td>
|
||||
<td class=cell>{{value.date}}</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
|
@ -4,17 +4,6 @@ const jetquery = @import("jetzig").jetquery;
|
|||
|
||||
pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
|
||||
_ = data;
|
||||
try request.repo.insert(.Artist, .{
|
||||
.id = 123,
|
||||
.name = "wilco",
|
||||
.album_num = 10,
|
||||
.song_num = 200,
|
||||
.play_count = 2700,
|
||||
.avg_album_score = 10.0,
|
||||
.avg_song_score = 10.0,
|
||||
.url = "/wilco",
|
||||
.aliased = false,
|
||||
});
|
||||
return request.render(.ok);
|
||||
}
|
||||
|
||||
|
|
@ -24,8 +13,45 @@ pub fn get(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig
|
|||
return request.render(.ok);
|
||||
}
|
||||
|
||||
pub fn post(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
|
||||
_ = data;
|
||||
pub fn post(request: *jetzig.Request) !jetzig.View {
|
||||
const Scrobble = struct {
|
||||
track: []u8,
|
||||
artist: []u8,
|
||||
album: []u8,
|
||||
date: i64,
|
||||
};
|
||||
|
||||
const lastfm = struct {
|
||||
username: []u8,
|
||||
scrobbles: []Scrobble,
|
||||
};
|
||||
|
||||
var root = try request.data(.object);
|
||||
|
||||
if (try request.file("upload")) |file| {
|
||||
const parsed = try std.json.parseFromSlice(lastfm, request.allocator, file.content, .{});
|
||||
|
||||
const history = parsed.value;
|
||||
|
||||
//std.debug.print("{s}", .{history.scrobbles[19].artist});
|
||||
|
||||
var scrobbles = try root.put("scrobbles", .array);
|
||||
for (history.scrobbles) |scrobble| {
|
||||
try scrobbles.append(scrobble);
|
||||
|
||||
const database_update = jetzig.database.Query(.RawScrobble)
|
||||
.insert(.{ .track = scrobble.track, .album = scrobble.album, .artist = scrobble.artist, .date = @divFloor(scrobble.date, 1000) });
|
||||
|
||||
try request.repo.execute(database_update);
|
||||
}
|
||||
}
|
||||
|
||||
var upload_table = try root.put("upload_table", .array);
|
||||
try upload_table.append("Track");
|
||||
try upload_table.append("Artist");
|
||||
try upload_table.append("Album");
|
||||
try upload_table.append("Date");
|
||||
|
||||
return request.render(.created);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
@partial partials/header
|
||||
<div>
|
||||
<span>Upload Last.fm or Spotify history file here (in json format).</span>
|
||||
</div>
|
||||
<form action="/" enctype="multipart/form-data" method="POST">
|
||||
<form action="/upload" enctype="multipart/form-data" method="POST">
|
||||
<label>Filename</label>
|
||||
<input type="text" name="description" />
|
||||
<label>File</label>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
<div>
|
||||
<span>Content goes here</span>
|
||||
</div>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
@partial partials/header
|
||||
<h1>File Uploaded Successfully</h1>
|
||||
|
||||
<h2>Scrobbles Added</h2>
|
||||
|
||||
@partial partials/table(table_data: .scrobbles, table_headers: .upload_table, table_context: .context)
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue