Skip to content

Instantly share code, notes, and snippets.

@quonic
Last active April 21, 2022 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quonic/bbc19d957ff960726ff4cb15f7c8adfe to your computer and use it in GitHub Desktop.
Save quonic/bbc19d957ff960726ff4cb15f7c8adfe to your computer and use it in GitHub Desktop.
Script to upload an image to a self hosted pictshare server from Greenshot via pwsh(Powershell 7)
#Requires -Version 7
# Deletes all posts from $LogFile
[CmdletBinding()]
param (
# Log file of all requests
[string]
$LogFile = "C:\temp\pictshare_posts.json"
)
begin {}
process {
Get-Content -Path $LogFile |
ConvertFrom-Json |
Where-Object { $_.delete_url} |
Select-Object -Property delete_url -Unique |
ForEach-Object {
Invoke-RestMethod -Uri $_.delete_url
}
# Clear log file
"[]" | Out-File -FilePath $LogFile
}
end {}
#Requires -Version 7
<#
.SYNOPSIS
Upload an image to a self hosted pictshare server from Greenshot via pwsh(Powershell 7)
.DESCRIPTION
This requires curl for windows to be installed and in PATH
Curl can be downloaded directly from: https://curl.se/download.html
or installed via chocolaty: https://community.chocolatey.org/packages/curl
choco install curl
In Greenshot
Settings -> Output
Storage location: C:\Temp\
Filename pattern: GreenShot
Image format: jpg
Create a new External command, under Settings -> Plugins -> Click on External command Plugin -> Configure -> New
Name: what ever you want here
Command: find and point to pwsh.exe
Argument: -F Path\to\this\script -Address consto.com
.EXAMPLE
PS C:\> script.ps1 -Address consto.com
Uploads $File to consto.com
.INPUTS
None
.OUTPUTS
None
.NOTES
General notes
#>
[CmdletBinding()]
param (
# Change the base url to match your Pictshare server
[Parameter(Mandatory)]
[string]
$Address,
# Change path of where you expect the jpg file to be
[string]
$File = "C:\Temp\GreenShot.jpg",
# Log file of all requests
[string]
$LogFile = "C:\temp\pictshare_posts.json",
[switch]
$IsNotHttps,
[switch]
$NoSaveToClipboard
)
begin {
$Protocol = if ($IsNotHttps){
"http:"
}else{
"https:"
}
}
process {
# Upload screenshot
$Response = $(curl -s -F "file=@$File" $Protocol//$Address/api/upload.php) | ConvertFrom-Json
if ($Response.status -like "ok") {
if ($NoSaveToClipboard){
# Don't save url to clipboard
}else{
Set-Clipboard -Value $Response.url
}
}
# Output response back from the pictshare server
$Response | ConvertTo-Json | Out-File -FilePath $LogFile -Append
}
end {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment