Skip to content

Commit

Permalink
catchup
Browse files Browse the repository at this point in the history
  • Loading branch information
donpdonp committed Jan 9, 2025
1 parent af6ffa4 commit 4a8950f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
18 changes: 9 additions & 9 deletions src/db/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ const Allocator = std.mem.Allocator;
const cache_dir = "./cache";

pub fn init(alloc: Allocator) !void {
const realpath = std.fs.Dir.realpathAlloc(std.fs.cwd(), alloc, cache_dir) catch unreachable;
std.posix.mkdir(cache_dir, 0o644) catch |err| {
const cwd = std.fs.cwd();
const cwd_path = std.fs.Dir.realpathAlloc(cwd, alloc, ".") catch unreachable;
const parts: []const []const u8 = &[_][]const u8{ cwd_path, cache_dir };
const cache_path = std.fs.path.join(alloc, parts) catch unreachable;
std.posix.mkdir(cache_path, 0o755) catch |err| {
if (err != error.PathAlreadyExists) return err;
warn("cache dir {s}", .{realpath});
};
warn("cache dir {s}", .{cache_path});
}

pub fn has(namespace: []const u8, key: []const u8, allocator: Allocator) bool {
Expand All @@ -20,23 +23,20 @@ pub fn has(namespace: []const u8, key: []const u8, allocator: Allocator) bool {
if (std.fs.cwd().access(keypath, .{ .mode = .read_only })) {
found = true;
} else |err| {
warn("dbfile did not find {s} {!}\n", .{ keypath, err });
warn("dbfile did not find {s} {!}", .{ keypath, err });
}
return found;
}

pub fn write(namespace: []const u8, key: []const u8, value: []const u8, allocator: Allocator) !void {
_ = cache_dir;
_ = namespace;
_ = allocator;
const dirpath = "Z"; //try std.fmt.allocPrint(allocator, "{s}/{s}", .{ cache_dir, namespace });
const dirpath = try std.fmt.allocPrint(allocator, "{s}/{s}", .{ cache_dir, namespace });
warn("MKDIR {s}\n", .{dirpath});
var dir = std.fs.Dir.makeOpenPath(std.fs.cwd(), dirpath, .{}) catch unreachable;
defer dir.close();
if (dir.createFile(key, .{ .truncate = true })) |*file| {
_ = try file.write(value);
file.close();
} else |err| {
warn("open write err {s} {s} {!}\n", .{ dirpath, key, err });
warn("open write err {s} {s} {any}\n", .{ dirpath, key, err });
}
}
5 changes: 2 additions & 3 deletions src/gui/gtk3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn find_gui_column(c_column: *config.ColumnInfo) ?*Column {
}

pub fn update_column_toots(column: *Column) void {
warn("update_column {s} {} toots {s}", .{
warn("update_column {any} {} toots {s}", .{
column.main.config.title,
column.main.toots.count(),
if (column.main.inError) @as([]const u8, "ERROR") else @as([]const u8, ""),
Expand Down Expand Up @@ -370,9 +370,8 @@ pub fn destroyTootBox(builder: *c.GtkBuilder) void {
pub fn makeTootBox(toot: *toot_lib.Type, column: *Column) *c.GtkBuilder {
warn("maketootbox toot #{s} {*} gui building {} images", .{ toot.id(), toot, toot.imgList.items.len });
const builder = c.gtk_builder_new_from_file("glade/toot.glade");
//const tootbox = builder_get_widget(builder, "tootbox");

//const id = toot.get("id").?.String;
//const id = toot.get("id").?.string;
const account = toot.get("account").?.object;
const author_acct = account.get("acct").?.string;

Expand Down
17 changes: 8 additions & 9 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -225,33 +225,32 @@ fn netback(command: *thread.Command) void {
if (command.verb.http.response_code >= 200 and command.verb.http.response_code < 300) {
if (command.verb.http.body.len > 0) {
const tree = command.verb.http.tree.array;
warn("netback tree is {!}", .{tree});
//warn("netback tree is {!}", .{tree});
if (@TypeOf(tree) == std.json.Array) {
column.inError = false;
warn("netback payload is array len {}", .{tree.items.len});
for (tree.items) |jsonValue| {
const item = jsonValue.object;
const toot = alloc.create(toot_lib.Type) catch unreachable;
toot.* = toot_lib.Type.init(item, alloc);
var toot = toot_lib.Type.init(item, alloc);
const id = toot.id();
warn("netback json create toot #{s} {*}", .{ id, toot });
if (column.toots.contains(toot)) {
warn("netback json create toot #{s} {any}", .{ id, toot });
if (column.toots.contains(&toot)) {
// dupe
} else {
const images = toot.get("media_attachments").?.array;
column.toots.sortedInsert(toot, alloc);
column.toots.sortedInsert(&toot, alloc);
const html = toot.get("content").?.string;
//var html = json_lib.jsonStrDecode(jstr, allocator) catch unreachable;
const root = html_lib.parse(html);
html_lib.search(root);
cache_update(toot, alloc);
cache_update(&toot, alloc);

for (images.items) |image| {
const img_url_raw = image.object.get("preview_url").?;
if (img_url_raw == .string) {
const img_url = img_url_raw.string;
warn("toot #{s} has img {s}", .{ toot.id(), img_url });
mediaget(toot, img_url, alloc);
mediaget(&toot, img_url, alloc);
} else {
warn("WARNING: image json 'preview_url' is not String: {}", .{img_url_raw});
}
Expand Down Expand Up @@ -292,7 +291,7 @@ fn photoback(command: *thread.Command) void {
const reqres = command.verb.http;
var account = reqres.toot.get("account").?.object;
const acct = account.get("acct").?.string;
warn("photoback! acct {s} type {s} size {}\n", .{ acct, reqres.content_type, reqres.body.len });
//warn("photoback! acct {s} type {s} size {}\n", .{ acct, reqres.content_type, reqres.body.len });
dbfile.write(acct, "photo", reqres.body, alloc) catch unreachable;
const cAcct = util.sliceToCstr(alloc, acct);
gui.schedule(gui.update_author_photo_schedule, @as(*anyopaque, @ptrCast(cAcct)));
Expand Down
2 changes: 1 addition & 1 deletion src/net.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn go(data: ?*anyopaque) callconv(.C) ?*anyopaque {
if (body.len > 0 and (actor.payload.http.content_type.len == 0 or
std.mem.eql(u8, actor.payload.http.content_type, "application/json; charset=utf-8")))
{
//warn("{s}\n", .{body}); // json dump
warn("{s}\n", .{body}); // json dump
if (std.json.parseFromSlice(std.json.Value, allocator, body, .{})) |value_tree| {
defer value_tree.deinit();
actor.payload.http.tree = value_tree.value;
Expand Down
5 changes: 2 additions & 3 deletions src/toot.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// toot.zig
const std = @import("std");
const warn = std.debug.print;
const Allocator = std.mem.Allocator;
const testing = std.testing;

const util = @import("util.zig");
const warn = util.log;

pub const Type = Toot();

Expand Down Expand Up @@ -74,7 +73,7 @@ pub fn Toot() type {
}

pub fn addImg(self: *Self, imgdata: ImgType) void {
warn("addImg toot {*}\n", .{self});
warn("addImg toot {any}", .{self});
self.imgList.append(imgdata) catch unreachable;
}

Expand Down

0 comments on commit 4a8950f

Please sign in to comment.