Skip to content

Instantly share code, notes, and snippets.

@ktwrd
Created July 5, 2023 03:48
Show Gist options
  • Save ktwrd/445c45e28baf80e12746077b38a59db9 to your computer and use it in GitHub Desktop.
Save ktwrd/445c45e28baf80e12746077b38a59db9 to your computer and use it in GitHub Desktop.
Pleroma Emoji Bulk Upload
<#
.Synopsis
Upload individual file or an entire directory to an emoji pack on your Pleroma-based instance.
.Example
Upload an entire directory to an emoji pack
.\PleromaBulkUpload.ps1 -Website "xenia.social" -ApiKey "xxxxx" -EmojiPackName skype -UploadDirectory $True -UploadDirectoryTarget .\skype
Upload one file to an emoji pack
.\PleromaBulkUpload.ps1 -Website "xenia.social" -ApiKey "xxxxx" -EmojiPackName skype -Filename apple.gif
#>
param(
[string]
$Website="xenia.social",
[string]
$ApiKey="",
[string]
$EmojiPackName="",
[ValidateScript({if ($_ -ne $null) {if ($_){ Test-Path $_}}})]
[string]
$Filename=$null,
[bool]
$UploadDirectory=$False,
[ValidateScript({if ($_ -ne $null) {if ($_){ Test-Path $_}}})]
[string]
$UploadDirectoryTarget=$null
)
function InitUploadEmoji([string]$file)
{
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
# $session.Cookies.Add((New-Object System.Net.Cookie("__Host-pleroma_key", $ApiKey, "/", $Website)))
$session.Cookies.Add((New-Object System.Net.Cookie("userLanguage", "en", "/", "$Website")))
$session.Cookies.Add((New-Object System.Net.Cookie("Admin-Token", $ApiKey, "/", "$Website")))
$session.Cookies.Add((New-Object System.Net.Cookie("Auth-Host", "$Website", "/", "$Website")))
$form = @{
file = Get-Item -Path $file
minorEdit = "true"
}
Invoke-WebRequest -UseBasicParsing -Uri "https://$Website/api/pleroma/emoji/packs/files?name=$EmojiPackName" `
-Method POST `
-WebSession $session `
-UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0" `
-Headers @{
"Accept" = "application/json, text/plain, */*"
"Accept-Language" = "en-US,en;q=0.5"
"Accept-Encoding" = "gzip, deflate, br"
"Origin" = "https://$Website"
"Sec-Fetch-Dest" = "empty"
"Sec-Fetch-Mode" = "cors"
"Sec-Fetch-Site" = "same-origin"
"Authorization" = "Bearer $ApiKey"
"TE" = "trailers"
}`
-ContentType "multipart/form-data;" `
-Form $form
}
if ($UploadDirectoryTarget -eq $null)
{
$UploadDirectoryTarget = "$(Get-Location)"
}
if ($UploadDirectory -eq $True)
{
Get-ChildItem $UploadDirectoryTarget | Where-Object {$_.Name -match '\.(gif|png|jpg|jpeg)$'} | Foreach-Object {
Write-Output $_.FullName
InitUploadEmoji -file $_.FullName
}
}
else
{
if (@(Test-Path $Filename) -ne $True)
{
Write-Output "Invalid location"
}
else
{
InitUploadEmoji -file $Filename
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment