void GenerateThumbs() { CreateThread("RinDB.GenerateThumbs", () => { ThumbGenerator.QueueThumb(RinDB.GetAll()); }); }
/// <summary> /// Add a new Image to the DB /// </summary> /// <param name="model">ImageModel of the image to be added</param> /// <returns>ImageModel unchanged</returns> public static ImageModel AddImage(ImageModel model) { if (ImageExists(model)) { model.fileUri = $@"{BASE_DIR}/{Uri.UnescapeDataString(model.fileUri)}"; return(model); } using (NpgsqlConnection con = new NpgsqlConnection(CONNECTION_STRING)) { con.Open(); using (NpgsqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT nextval('images_index_seq');"; model.id = $"{cmd.ExecuteScalar()}{model.timeadded}".ToBase60(); cmd.CommandText = $"INSERT INTO images (id, name, timeadded, fileuri, isnsfw) VALUES('{model.id}', '{model.name}', '{model.timeadded}', '{model.fileUri}', '{model.isnsfw}')"; cmd.ExecuteNonQuery(); if (model.tags != null) { foreach (TagModel tag in model.tags) { AddTag(model.id, tag.id); } } } } model.fileUri = $@"{BASE_DIR}/{Uri.UnescapeDataString(model.fileUri)}"; ThumbGenerator.QueueThumb(model); return(model); }
private Response GetOrGenerateThumb(ImageModel image) { string ext = Path.GetExtension(image.fileUri); if (!File.Exists($"{RinDB.THUMB_DIR}/{image.id}{ext}")) { if (!Directory.Exists(RinDB.THUMB_DIR)) { Directory.CreateDirectory(RinDB.THUMB_DIR); } ThumbGenerator.QueueThumb(image); return(Response.AsRedirect("/res/img/DefaultThumb.png")); } return(Response.FromImage($"{RinDB.THUMB_DIR}/{image.id}{ext}")); }
void DoBuild(Dictionary <string, string[]> buildList) { foreach (string item in buildList.Keys) { Write($"Building: {item}...", false); string[] dir = Directory.GetFiles($@"{RinDB.BASE_DIR}/{item}", "*", SearchOption.AllDirectories); foreach (string f in dir) { string file = f.Replace("\\", "/"); file = file.Replace($@"{RinDB.BASE_DIR}/", ""); string name = Path.GetFileNameWithoutExtension(file); long epoch = long.Parse(name.Substring(1, name.IndexOf(']') - 1)); name = name.Remove(0, epoch.ToString().Length + 3); name = Uri.EscapeDataString(name); string id = file.ToBase60(); DBUpdateQueue.QueueCommand($"INSERT INTO images (id, fileuri, timeadded, name, isnsfw) VALUES('{id}', '{Uri.EscapeDataString(file)}', '{epoch}', '{name}', '{file.Contains("NSFW")}');"); //cmd.CommandText = $"INSERT INTO images (id, fileuri, timeadded, name, isnsfw) VALUES('{id}', '{Uri.EscapeDataString(file)}', '{epoch}', '{name}', '{file.Contains("NSFW")}');"; if (buildList[item] != null) { foreach (string tag in buildList[item]) { string tagID = tag.ToBase60(); //cmd.CommandText += $"INSERT INTO tagmap VALUES('{tagID}{id}','{id}', '{tagID}');"; DBUpdateQueue.QueueCommand($"INSERT INTO tagmap VALUES('{tagID}{id}','{id}', '{tagID}');"); } } //cmd.ExecuteNonQuery(); ThumbGenerator.QueueThumb(new ImageModel() { id = id, fileUri = $@"{RinDB.BASE_DIR}/{file}" }); } Write(" Done!"); } }