Ejemplo n.º 1
0
        public IActionResult Upload(IFormFile myfile)
        {
            Guid   guid           = Guid.NewGuid();
            string actualFileName = $"{guid}-{myfile.FileName}";
            string finalFileName  = Path.Combine(_environment.WebRootPath, "uploads", actualFileName);

            using var fs = new FileStream(finalFileName, FileMode.CreateNew);
            myfile.CopyTo(fs);

            var db = new ImageDb(_connectionString);

            db.AddImage(actualFileName);

            return(Redirect("/"));
        }
Ejemplo n.º 2
0
        public IActionResult Upload(IFormFile myfile, string password)
        {
            Guid   guid           = Guid.NewGuid();
            string actualFileName = $"{guid}-{myfile.FileName}";
            string finalFileName  = Path.Combine(_environment.WebRootPath, "uploads", actualFileName);

            using var fs = new FileStream(finalFileName, FileMode.CreateNew);
            myfile.CopyTo(fs);

            var db      = new ImageDb(_connectionString);
            int imageId = db.AddImage(actualFileName, password);

            UploadViewModel vm = new UploadViewModel();

            vm.Image = db.GetImages().FirstOrDefault(i => i.Id == imageId);
            vm.Link  = $"http://localhost:53644/home/ViewImage?id={imageId}";
            return(View(vm));
        }
Ejemplo n.º 3
0
        public async Task NewImage(string name, string url = null, [Remainder] string str = "")
        {
            await Context.Channel.TriggerTypingAsync();

            bool insider = Context.Guild.Id == 418900885079588884;

            url ??= Context.Message.Attachments.FirstOrDefault()?.Url;

            if (!insider)
            {
                if (!PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus))
                {
                    await Context.Channel.SendMessageAsync($"This server does not have Pro Guild+. `{Program.GetPrefix(Context)}pro`");

                    return;
                }

                if ((await ImageDb.GetImages(name, 0)).Any())
                {
                    await Context.Channel.SendMessageAsync($"There is already a default image command called **{name}**. It will be replaced with your custom one.");
                }
            }

            if (url == null)
            {
                await Context.Channel.SendMessageAsync("Can't get your attachment, there probably isn't one. *Heh, dummy...*");

                return;
            }

            url = url.EndsWith(".gifv") ? url.Replace(".gifv", ".gif") : url;
            url = url.EndsWith(".mp4") ? url.Replace(".mp4", ".gif") : url;

            if (ImgurAPI.RateLimit.ClientRemaining < 50)
            {
                await ReplyAsync("Not enough imgur credits to upload. Please try again later.");

                return;
            }

            string albumId;
            string albumName = insider ? name : name + Context.Guild.Id;

            if (!ImageDb.AlbumExists(albumName))
            {
                albumId = (await ImgurAPI.CreateAlbumAsync(albumName)).Id;
                await ImageDb.CreateAlbum(albumName, albumId);
            }
            else
            {
                albumId = ImageDb.GetAlbum(albumName).AlbumId;
            }

            var iImage = await ImgurAPI.UploadImageAsync(url, albumId);

            var img = await ImageDb.AddImage(name.ToLower(), iImage.Link, insider? 0 : Context.Guild.Id);

            if (!ReactionImageCommands.Contains(name.ToLower()))
            {
                ReactionImageCommands.Add(name.ToLower());
            }

            await ImgurAPI.EditImageAsync(iImage.Id.ToString(), null, img.Id.ToString());

            var rl = ImgurAPI.RateLimit;
            await ImageUtil.UploadReactionImage(img, Context.Channel);

            await Context.Channel.SendMessageAsync($"{rl.ClientRemaining-20}/{rl.ClientLimit} imgur credits remaining.", false, ImageUtil.ToEmbed(img).Build());
        }