public override void Handle(HttpRequest request, HttpResponse response) { if (string.IsNullOrEmpty(request.Headers["key"])) { response.Drop("no key given"); return; } var key = KeysRepository.Find(request.Headers["key"]); if (key == null) { response.Drop("no key found"); return; } if (!new[] { AccessLevel.Admin, AccessLevel.Moderator }.ToList().Contains(key.Level)) { response.Drop("no access"); return; } if (request.Files["grekan"] == null) { response.Drop("no grekan given"); return; } var file = request.Files["grekan"]; using (var image = Image.FromStream(file.InputStream)) { if (image.Width != 960 && image.Height != 960) { response.Drop("image is not 960x960"); return; } var ms = new MemoryStream(); image.Save(ms, ImageFormat.Jpeg); ImageRepository.Add(ms.ToArray()); Logger.Info($"User noted as '{key.Note}' just added a new image."); Logger.Info($"http://backend.grekan.tk/get_image?id={ImageRepository.LastId()}"); ImageRepository.ResetInternalPointer(); response.WriteLine("s u c c"); } }
public override void Handle(HttpRequest request, HttpResponse response) { if (string.IsNullOrEmpty(request.Headers["key"])) { response.Drop("no key given"); return; } var key = KeysRepository.Find(request.Headers["key"]); if (key == null) { response.Drop("no key found"); return; } if (key.Level != AccessLevel.Admin) { response.Drop("no access"); return; } int id; if (!int.TryParse(request.QueryString["id"], out id)) { response.Drop("Non-int id given", 403); return; } if (id < 0 || id >= ImageRepository.GetCount()) { response.Drop("id not in range"); return; } ImageRepository.Delete(id); ImageRepository.ResetInternalPointer(); response.WriteLine("s u c c"); }