Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attachments on s3 and numerous other fixes.
including - fixes on deleteCard and moveCardTo/FromBoard - fixes on checklists and checkItems - renaming and other quibbles missing - comments - custom fields - testing? I guess I'll just test manually.
- Loading branch information
Showing
8 changed files
with
289 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,100 @@ | |||
package main | |||
|
|||
import ( | |||
"bytes" | |||
"io" | |||
"io/ioutil" | |||
"mime/multipart" | |||
"net/http" | |||
"os" | |||
|
|||
"github.com/minio/minio-go" | |||
) | |||
|
|||
func saveToS3(id, trelloURL string) (err error) { | |||
// download file from trello | |||
file, err := ioutil.TempFile("", "trello-permissions-") | |||
if err != nil { | |||
file.Close() | |||
return | |||
} | |||
|
|||
resp, err := http.Get(trelloURL) | |||
if err != nil { | |||
file.Close() | |||
return | |||
} | |||
|
|||
_, err = io.Copy(file, resp.Body) | |||
if err != nil { | |||
file.Close() | |||
return | |||
} | |||
file.Close() | |||
|
|||
// upload to s3 | |||
_, err = ms3.FPutObject(s.S3BucketName, id, file.Name(), | |||
minio.PutObjectOptions{}) | |||
|
|||
return | |||
} | |||
|
|||
func restoreFromS3(attId, attName, cardId, token string) (err error) { | |||
file, err := ioutil.TempFile("", "trello-permissions-") | |||
if err != nil { | |||
return | |||
} | |||
|
|||
path := file.Name() | |||
file.Close() | |||
|
|||
// download file from s3 | |||
err = ms3.FGetObject(s.S3BucketName, | |||
attId, | |||
path, | |||
minio.GetObjectOptions{}) | |||
if err != nil { | |||
return | |||
} | |||
|
|||
// upload files to trello | |||
file, err = os.Open(path) | |||
if err != nil { | |||
return | |||
} | |||
defer file.Close() | |||
|
|||
post := &bytes.Buffer{} | |||
writer := multipart.NewWriter(post) | |||
part, err := writer.CreateFormFile("file", path) | |||
if err != nil { | |||
return | |||
} | |||
|
|||
_, err = io.Copy(part, file) | |||
if err != nil { | |||
return | |||
} | |||
|
|||
writer.WriteField("name", attName) | |||
writer.WriteField("key", s.TrelloApiKey) | |||
writer.WriteField("token", token) | |||
|
|||
err = writer.Close() | |||
if err != nil { | |||
return | |||
} | |||
|
|||
req, err := http.NewRequest("POST", | |||
"https://api.trello.com/1/cards/"+cardId+"/attachments", post) | |||
if err != nil { | |||
return | |||
} | |||
req.Header.Set("Content-Type", writer.FormDataContentType()) | |||
_, err = http.DefaultClient.Do(req) | |||
return | |||
} | |||
|
|||
func deleteFromS3(id string) (err error) { | |||
return ms3.RemoveObject(s.S3BucketName, id) | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.