mirror of
https://github.com/seigler/slack-cleanup
synced 2025-07-27 01:36:12 +00:00
Updated README and cleaned up output
This commit is contained in:
parent
edf99b52c0
commit
3d9abde17a
3 changed files with 16 additions and 6 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -12,3 +12,6 @@
|
||||||
|
|
||||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||||
.glide/
|
.glide/
|
||||||
|
|
||||||
|
# Remove the build binary
|
||||||
|
slack-cleanup
|
||||||
|
|
10
README.md
10
README.md
|
@ -6,7 +6,11 @@ A program for cleaning up slack files to free up space.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
You will need to generate an API token that has permission to delete files. If you do not have administrator
|
Install Slack Cleanup
|
||||||
privileges you will only be able to delete your own files. Generate an API token at the following link:
|
|
||||||
|
|
||||||
[Legacy Tokens](https://api.slack.com/custom-integrations/legacy-tokens)
|
go get github.com/madecomfy/slack-cleanup
|
||||||
|
|
||||||
|
You will need to generate an API token that has permission to delete files. Add this token to your environment
|
||||||
|
variables (we use Direnv to manage env vars).
|
||||||
|
|
||||||
|
export SLACK_API_TOKEN=xoxp-111111-1111111-1111111-1111111-111111
|
||||||
|
|
9
main.go
9
main.go
|
@ -10,12 +10,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Files contains the list of files we want to clean
|
// Files contains the list of files we want to delete
|
||||||
type Files struct {
|
type Files struct {
|
||||||
FileList []File `json:"files"`
|
FileList []File `json:"files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// File is an individual file we wish to remove from Slack
|
// File is an individual file we wish to delete from Slack
|
||||||
type File struct {
|
type File struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count := 0
|
||||||
for _, file := range files.FileList {
|
for _, file := range files.FileList {
|
||||||
req, err := http.NewRequest("GET", "https://slack.com/api/files.delete", nil)
|
req, err := http.NewRequest("GET", "https://slack.com/api/files.delete", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,7 +67,7 @@ func main() {
|
||||||
httpClient := &http.Client{}
|
httpClient := &http.Client{}
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
_, err = ioutil.ReadAll(resp.Body)
|
_, err = ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,6 +75,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("File", file.ID, "successfully deleted")
|
fmt.Println("File", file.ID, "successfully deleted")
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Fin.", count, "files successfully deleted")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue