commands

package
v0.8.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreditsCmd = &cobra.Command{
	Use:                   "credits <delete hash>",
	Short:                 "Rate Limits",
	DisableFlagsInUseLine: true,
	Example:               "imgur credits",
	RunE: func(cmd *cobra.Command, args []string) error {
		client := utils.CreateClient()

		limit, _, err := client.RateLimits()
		if err != nil {
			utils.Notify.Push("Error!", err.Error(), "", notificator.UR_CRITICAL)
			log.Fatal("Error Get Rate Limits: " + err.Error())
		}

		fmt.Printf("Client Total Credits     - %d\n", limit.Data.ClientLimit)
		fmt.Printf("Client Remaining Credits - %d\n", limit.Data.ClientRemaining)
		fmt.Printf("User Total Credits       - %d\n", limit.Data.UserLimit)
		fmt.Printf("User Remaining Credits   - %d\n", limit.Data.UserRemaining)
		fmt.Printf("User Credits Reset       - %s\n", time.Unix(int64(limit.Data.UserReset), 0).Format("2006-01-02 15:04:05 -0700"))

		return nil
	},
}
View Source
var DeleteCmd = &cobra.Command{
	Use:                   "delete <delete hash>",
	Short:                 "Delete image from Imgur by Delete Hash",
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	Example:               "imgur delete DSdXVa0PZwsUJgB",
	RunE: func(cmd *cobra.Command, args []string) error {
		client := utils.CreateClient()

		_, _, err := client.DeleteImageUnAuthed(args[0])
		if err != nil {
			utils.Notify.Push("Error!", err.Error(), "", notificator.UR_CRITICAL)
			log.Fatal("Error delete image: " + err.Error())
		}

		fmt.Println("Image deleted!")

		utils.Notify.Push("Deleted!", "", "", notificator.UR_NORMAL)

		return nil
	},
}
View Source
var InfoCmd = &cobra.Command{
	Use:                   "info <image id>",
	Short:                 "Image Info",
	Long:                  "Get Image Info",
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	Example:               "imgur info n744BL9",
	RunE: func(cmd *cobra.Command, args []string) error {
		client := utils.CreateClient()

		data, _, err := client.GetImageInfo(args[0])
		if err != nil {
			utils.Notify.Push("Error!", err.Error(), "", notificator.UR_CRITICAL)
			log.Fatal("Error get image info: " + err.Error())
		}

		fmt.Printf("ID          - %s\n", data.Data.ID)
		fmt.Printf("URL         - %s\n", "https://cdn.magicuser.cf/"+data.Data.IDExt)
		fmt.Printf("Views       - %d\n", data.Data.Views)
		fmt.Printf("Size        - %s\n", u.Bytes(uint64(data.Data.Size)))
		fmt.Printf("Height      - %d\n", data.Data.Height)
		fmt.Printf("Width       - %d\n", data.Data.Width)
		fmt.Printf("Type        - %s\n", data.Data.MimeType)
		fmt.Printf("Upload Date - %s\n", time.Unix(int64(data.Data.Datetime), 0).Format("2006-01-02 15:04:05 -0700"))
		fmt.Printf("Bandwidth   - %s\n", u.Bytes(uint64(data.Data.Bandwidth)))

		return nil
	},
}
View Source
var UploadCmd = &cobra.Command{
	Use:                   "upload <path to file or url>",
	Short:                 "Upload image to Imgur",
	Args:                  cobra.MinimumNArgs(1),
	DisableFlagsInUseLine: true,
	Example:               "imgur upload Pictures/Screenshot.png",
	RunE: func(cmd *cobra.Command, args []string) error {
		client := utils.CreateClient()

		f, err := os.Stat(args[0])

		if err == nil {
			if f.IsDir() {
				log.Fatalf("%s is dir!", args[0])
			}

			data, _, err := client.UploadImageFromFile(args[0], "")
			if err != nil {
				utils.Notify.Push("Error!", err.Error(), "", notificator.UR_CRITICAL)
				log.Fatal("Error upload image to Imgur: " + err.Error())
			}

			printLink(data)
		} else {
			data, _, err := client.UploadImageFromURL(args[0], "")
			if err != nil {
				utils.Notify.Push("Error!", err.Error(), "", notificator.UR_CRITICAL)
				log.Fatal("Error upload image to Imgur: " + err.Error())
			}

			printLink(data)
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL