mirror of
https://github.com/paradizelost/Powershell-Public.git
synced 2024-11-25 02:04:43 -06:00
Update teedy.ps1
This commit is contained in:
parent
1d5e64b9fe
commit
f5d6832323
92
teedy.ps1
92
teedy.ps1
@ -2,6 +2,7 @@ $siteurl = "https://demo.teedy.io"
|
|||||||
$headers = get-sitelogin
|
$headers = get-sitelogin
|
||||||
$global:taghash=@{}
|
$global:taghash=@{}
|
||||||
function get-sitelogin(){
|
function get-sitelogin(){
|
||||||
|
|
||||||
$tologin=@{username="demo";password="password";}
|
$tologin=@{username="demo";password="password";}
|
||||||
try{
|
try{
|
||||||
$loginresponse = Invoke-webrequest -Uri "$siteurl/api/user/login" -Method POST -Body $tologin
|
$loginresponse = Invoke-webrequest -Uri "$siteurl/api/user/login" -Method POST -Body $tologin
|
||||||
@ -30,16 +31,24 @@ function New-Tag(){
|
|||||||
$ParentTagName="",
|
$ParentTagName="",
|
||||||
$color="3a87ad"
|
$color="3a87ad"
|
||||||
)
|
)
|
||||||
|
if($tagname.length -gt 36){
|
||||||
|
$tagname = $tagname.substring(0,36)
|
||||||
|
}
|
||||||
try{
|
try{
|
||||||
$colorcode = ("{0:X}" -f [drawing.Color]::FromName($color).toargb() ).Substring(2)
|
if($color -eq "3a87ad"){
|
||||||
|
$colorcode="$color"
|
||||||
|
} else {
|
||||||
|
$colorcode = ("{0:X}" -f [drawing.Color]::FromName($color).toargb()).Substring(2)
|
||||||
|
}
|
||||||
}catch{
|
}catch{
|
||||||
$error[0]
|
$error[0]
|
||||||
write-host "Unable to determine color code. Using default blue."
|
write-host "Unable to determine color code. Using default blue."
|
||||||
$colorcode = '3a87ad'
|
$colorcode = '3a87ad'
|
||||||
}
|
}
|
||||||
Update-TagHash
|
Update-TagHash
|
||||||
|
try{
|
||||||
if($global:taghash[$TagName]){
|
if($global:taghash[$TagName]){
|
||||||
throw "TAG $tagname already exists."
|
return "TAG $tagname already exists."
|
||||||
}
|
}
|
||||||
if((-not($global:taghash[$ParentTagName])) -and ($ParentTagName -ne '') ){
|
if((-not($global:taghash[$ParentTagName])) -and ($ParentTagName -ne '') ){
|
||||||
$parentTagID = (New-Tag -TagName $ParentTagName -ParentTagName '').id
|
$parentTagID = (New-Tag -TagName $ParentTagName -ParentTagName '').id
|
||||||
@ -51,14 +60,17 @@ function New-Tag(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$mytagtocreate = @{
|
$mytagtocreate = @{
|
||||||
name=$TagName;
|
name=$TagName -replace ' ','_' -replace ':','_';
|
||||||
parent=$parentTagID;
|
parent=$parentTagID;
|
||||||
color="#$colorcode";
|
color="#$colorcode";
|
||||||
}
|
}
|
||||||
$mytagtocreate
|
#$mytagtocreate
|
||||||
$newtagid = Invoke-RestMethod -uri "$siteurl/api/tag" -Headers $headers -Method PUT -body $mytagtocreate -ContentType 'application/x-www-form-urlencoded'
|
$newtagid = Invoke-RestMethod -uri "$siteurl/api/tag" -Headers $headers -Method PUT -body $mytagtocreate -ContentType 'application/x-www-form-urlencoded'
|
||||||
Update-TagHash
|
Update-TagHash
|
||||||
$newtagid
|
} catch {
|
||||||
|
$error[0]
|
||||||
|
}
|
||||||
|
$newtagid.id
|
||||||
}
|
}
|
||||||
function Remove-Tag(){
|
function Remove-Tag(){
|
||||||
param(
|
param(
|
||||||
@ -128,6 +140,7 @@ function Attach-File(){
|
|||||||
fileID=$file;
|
fileID=$file;
|
||||||
id=$document
|
id=$document
|
||||||
}
|
}
|
||||||
|
$toattach
|
||||||
Invoke-RestMethod -uri "$siteurl/api/file/$file/attach" -Headers $headers -Method POST -Body $toattach -ContentType 'application/x-www-form-urlencoded'
|
Invoke-RestMethod -uri "$siteurl/api/file/$file/attach" -Headers $headers -Method POST -Body $toattach -ContentType 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,6 +157,9 @@ function New-Document(){
|
|||||||
$fileids= Add-File -Files $file
|
$fileids= Add-File -Files $file
|
||||||
}
|
}
|
||||||
$tagid=$taghash[$tag].id
|
$tagid=$taghash[$tag].id
|
||||||
|
if(-not $tagid){
|
||||||
|
$tagid=new-tag -TagName $tag
|
||||||
|
}
|
||||||
$doctocreate=@{
|
$doctocreate=@{
|
||||||
title=$title;
|
title=$title;
|
||||||
language="eng";
|
language="eng";
|
||||||
@ -153,6 +169,31 @@ function New-Document(){
|
|||||||
$newdocid = (Invoke-RestMethod -uri "$siteurl/api/document" -Headers $headers -Method PUT -body $doctocreate -ContentType 'application/x-www-form-urlencoded').id
|
$newdocid = (Invoke-RestMethod -uri "$siteurl/api/document" -Headers $headers -Method PUT -body $doctocreate -ContentType 'application/x-www-form-urlencoded').id
|
||||||
attach-file -documentid $newdocid -fileid $fileids
|
attach-file -documentid $newdocid -fileid $fileids
|
||||||
}
|
}
|
||||||
|
function New-multitagDocument(){
|
||||||
|
param(
|
||||||
|
$title,
|
||||||
|
$language='eng',
|
||||||
|
#$tags='',
|
||||||
|
$tag,
|
||||||
|
$file
|
||||||
|
)
|
||||||
|
if($file){
|
||||||
|
$fileids= Add-File -Files $file
|
||||||
|
}
|
||||||
|
update-taghash
|
||||||
|
$tagid=$taghash[$tag].id
|
||||||
|
if(-not $tagid){
|
||||||
|
$tagid=new-tag -TagName $tag
|
||||||
|
}
|
||||||
|
$doctocreate=@{
|
||||||
|
title=$title;
|
||||||
|
language=$language;
|
||||||
|
tags= @{'0f142bff-7922-4c70-8ad2-f492cfd2e5ec';'07002700-01d8-4547-80b9-c59a7c80f2d6'};
|
||||||
|
}
|
||||||
|
$doctocreate
|
||||||
|
$newdocid = (Invoke-RestMethod -uri "$siteurl/api/document" -Headers $headers -Method PUT -body $doctocreate -ContentType 'application/x-www-form-urlencoded').id
|
||||||
|
attach-file -documentid $newdocid -fileid $fileids
|
||||||
|
}
|
||||||
Function Add-File(){
|
Function Add-File(){
|
||||||
param(
|
param(
|
||||||
$Files
|
$Files
|
||||||
@ -166,6 +207,47 @@ Function Add-File(){
|
|||||||
}
|
}
|
||||||
$fileids
|
$fileids
|
||||||
}
|
}
|
||||||
|
function Add-Directory(){
|
||||||
|
param(
|
||||||
|
$AnchorTag='DirUploadTest',
|
||||||
|
$Directory='C:\Users\dan\teedytest',
|
||||||
|
[switch]$DontUseExistingTags,
|
||||||
|
[switch]$OnlyCreateTags
|
||||||
|
)
|
||||||
|
Update-TagHash
|
||||||
|
if(-not($taghash[$AnchorTag])){
|
||||||
|
new-tag -TagName $AnchorTag
|
||||||
|
}
|
||||||
|
$directories = get-childitem -Path $directory -Directory -Recurse
|
||||||
|
foreach($mydirectory in $directories){
|
||||||
|
$myparts = @(($mydirectory.fullname -replace [regex]::escape($directory),'').substring(1) -split '\\')
|
||||||
|
#$mydirectory.FullName
|
||||||
|
#$myparts.count
|
||||||
|
for($i=0;$i -lt $myparts.count;$i++){
|
||||||
|
$myparts[$i]=$myparts[$i] -replace ' ','_' -replace ':',''
|
||||||
|
if(-not($taghash[$myparts[$i]])){
|
||||||
|
if($i -eq 0){
|
||||||
|
write-host "Creating Tag $($myparts[$i])"
|
||||||
|
new-tag -TagName $myparts[$i] -ParentTagName $AnchorTag
|
||||||
|
} else{
|
||||||
|
write-host "Creating Tag $($myparts[$i])"
|
||||||
|
new-tag -TagName $myparts[$i] -ParentTagName $myparts[$i-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$newtagname = $myparts[-1]
|
||||||
|
if(-not $OnlyCreateTags){
|
||||||
|
$files = get-childitem -Path $mydirectory.FullName -File | select-object -ExpandProperty FullName
|
||||||
|
if($files.count -gt 0){
|
||||||
|
if((split-path $files[0] -parent) -eq $Directory){
|
||||||
|
New-Document -title $mydirectory.FullName -tag $AnchorTag -file $files
|
||||||
|
} else {
|
||||||
|
New-Document -title $mydirectory.FullName -tag $newtagname -file $files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$documentlist = Invoke-RestMethod -uri "$siteurl/api/document/list" -Headers $headers -Method GET | select-object -ExpandProperty documents
|
$documentlist = Invoke-RestMethod -uri "$siteurl/api/document/list" -Headers $headers -Method GET | select-object -ExpandProperty documents
|
||||||
if($documentlist){write-host "Got docs"}
|
if($documentlist){write-host "Got docs"}
|
||||||
$filelist = Invoke-RestMethod -uri "$siteurl/api/file/list" -Headers $headers -Method GET |Select-Object -ExpandProperty Files
|
$filelist = Invoke-RestMethod -uri "$siteurl/api/file/list" -Headers $headers -Method GET |Select-Object -ExpandProperty Files
|
||||||
|
Loading…
Reference in New Issue
Block a user