Skip to content

Add upload history log#23

Open
artixnous wants to merge 3 commits intotremby:mainfrom
artixnous:main
Open

Add upload history log#23
artixnous wants to merge 3 commits intotremby:mainfrom
artixnous:main

Conversation

@artixnous
Copy link

One might need to delete something later on

Copy link
Owner

@tremby tremby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I was prepared on clicking the link to this PR to say "nope I want to keep it simple" but then I looked at the changeset and this is very simple.

I like it.

I think I would prefer to make this optional, however. I think it should be opt-in, via an environment variable. Maybe if IMGUR_LOG_FILE is set, log it to that file, and so at the same time we let the user choose where. That also takes the responsibility for making sure that file doesn't end up ridiculously huge off our plate. (A user who uses this a lot might choose to make some log rotating daemon take care of it, for example.)

I've added a couple of comments.

In addition, please add something to the readme about this. I can do this if you don't want to.

After you've addressed them, please squash your commits (or I can do it for you if you prefer); I don't want the parts of the commits which undo and redo the recent changes, which I think must have crept in when you rebased.

Thanks!

imgur.sh Outdated
echo $url
echo "Delete page: https://imgur.com/delete/$delete_hash" >&2
delete_page="https://imgur.com/delete/$delete_hash"
echo $url | sed 's/^http:/https:/'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a merge error; the sed has crept back in. Please undo that.

Set delete_page right after delete_hash gets set, then echo the URL, then echo the delete page to stderr.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only set $delete_page because it's used again below in logging; I do this for every variable used more than once. The logging echo could perfectly use "https://imgur.com/delete/$delete_hash" instead. Opinion?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion. The only important thing to me here was to not let sed creep back in, which would be a regression. Then I was dictating the order of lines but I don't feel that strongly about it. I wasn't complaining about making an extra variable -- I see why you did that and it makes sense.

if [ $# -gt 0 ]; then
clip+=$'\n'
fi
# Keep a log of the uploads
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick, but please add a blank line before this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

imgur.sh Outdated
clip+=$'\n'
fi
# Keep a log of the uploads
echo "$(date +"%Y/%m/%d_%H:%M:%S") $file $url $delete_page" >> $HOME/.imgur.sh.log
Copy link
Owner

@tremby tremby Feb 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's wrap this in a conditional.

    if [ -n "${IMGUR_LOG_FILE-}" ]; then
    

    should do it. (That trailing dash is on purpose.)

  • Then append it to that file. (Nitpick: I like no space between the >> and the file.)

  • Please also use the ISO date format (date -Isecond), and use a tab character between each pair of columns.

I'm not sure how valuable $file is, but short of checking whether it's stdin or a URL or a file and maybe running realpath on it, I don't know what to do. Probably just keep it simple and leave it how you are logging it.

Copy link
Author

@artixnous artixnous Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditional and date format done, although in my local copy I kept the original date format as -Isecond makes the date string unnecessarily long and short width terminals will wrap the output earlier. I also re-ordered the variables to print $file at the end, as this makes the columns nicely justified instead of stair-cased.

@artixnous
Copy link
Author

artixnous commented Feb 21, 2022

I'm not well versed in git, I'm an old-timer svn fella, so I'm not sure how to correctly make the changes appear in this PR; shall I create a new PR instead after you agree or not to my comments above?
This is the revised script.
https://gist.github.com/artixnous/8e212d4c1409b9d72aead48938cdc517

@tremby
Copy link
Owner

tremby commented Mar 8, 2022

I'm not well versed in git, I'm an old-timer svn fella, so I'm not sure how to correctly make the changes appear in this PR

Just push the new commits, which you presumably made on the same local branch, to the same remote branch you pushed to before, and they'll appear here.

@tremby
Copy link
Owner

tremby commented Mar 8, 2022

In other words, probably just git push.

@artixnous
Copy link
Author

Sorry for the long absence, been very busy lately. I got this in my personal logs:

2022/04/06_21:37:42	https://i.imgur.com/rqGzjTC.png	https://imgur.com/delete/fEjlHCSh2bgzNkM	/tmp/20220406-213736.png
2022/04/21_20:10:53	https://i.imgur.com/cBRey0E.png	https://imgur.com/delete/NCO2XiaEmDNgSZO	/tmp/20220421-201040.png
2022/04/21_20:12:34	<!doctype html>
<html lang="en">
<head>
...
    <title>Imgur overloaded. Hang in there with kittens</title>
...
</head>
<body>
...
            <h1>Imgur is over capacity!</h1>
            <p>Sorry! We're busy running around with our hair on fire because Imgur
                is over capacity! This can happen when the site is under a very heavy
                load, or while we're doing maintenance.
                <br /><br />
                Please <a href="/">try again</a> in a few minutes.
...
</body>
</html>	/tmp/20220421-201224.png

It's obviously very rare. I must also clarify here that I only saw this in the log as I feed the output of some screen grabber directly to imgur.sh. My workaround is a match test just after the first echo
[[ $url =~ "overload" ]] && exit 1
This way the user will see the error in the console but it won't make it to the log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants