Import Slack uploads if present in zip archive. (#4088)

* Import Slack uploads if present in zip archive.

This is part 3 of PLT-4280, to support importing file uploads when
importing from Slack. It is assumed the uploads in the zip archive will
be present as per the output of slack-advanced-exporter:

https://github.com/grundleborg/slack-advanced-exporter

If the uploads are not present (ie. this is a vanilla Slack export
archive) uploads are treated in the same way as before this patch,
providing only a link to the upload on Slack's servers.

* Update to new Files API.
Этот коммит содержится в:
George Goldberg
2016-10-12 14:31:05 +01:00
коммит произвёл Harrison Healey
родитель 1b0c1eb3ae
Коммит 5ca05124cf
3 изменённых файлов: 102 добавлений и 5 удалений

Просмотреть файл

@@ -4,6 +4,9 @@
package api
import (
"bytes"
"io"
l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
@@ -52,3 +55,28 @@ func ImportChannel(channel *model.Channel) *model.Channel {
return sc
}
}
func ImportFile(file io.Reader, teamId string, channelId string, userId string, fileName string) (*model.FileInfo, error) {
buf := bytes.NewBuffer(nil)
io.Copy(buf, file)
data := buf.Bytes()
previewPathList := []string{}
thumbnailPathList := []string{}
imageDataList := [][]byte{}
fileInfo, err := doUploadFile(teamId, channelId, userId, fileName, data)
if err != nil {
return nil, err
}
if fileInfo.PreviewPath != "" || fileInfo.ThumbnailPath != "" {
previewPathList = append(previewPathList, fileInfo.PreviewPath)
thumbnailPathList = append(thumbnailPathList, fileInfo.ThumbnailPath)
imageDataList = append(imageDataList, data)
}
go handleImages(previewPathList, thumbnailPathList, imageDataList)
return fileInfo, nil
}