当前位置: 首页>>代码示例>>Golang>>正文


Golang model.FileInfo类代码示例

本文整理汇总了Golang中github.com/mattermost/platform/model.FileInfo的典型用法代码示例。如果您正苦于以下问题:Golang FileInfo类的具体用法?Golang FileInfo怎么用?Golang FileInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileInfo类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Save

func (fs SqlFileInfoStore) Save(info *model.FileInfo) StoreChannel {
	storeChannel := make(StoreChannel, 1)

	go func() {
		result := StoreResult{}

		info.PreSave()
		if result.Err = info.IsValid(); result.Err != nil {
			storeChannel <- result
			close(storeChannel)
			return
		}

		if err := fs.GetMaster().Insert(info); err != nil {
			result.Err = model.NewLocAppError("SqlFileInfoStore.Save", "store.sql_file_info.save.app_error", nil, err.Error())
		} else {
			result.Data = info
		}

		storeChannel <- result
		close(storeChannel)
	}()

	return storeChannel
}
开发者ID:Rudloff,项目名称:platform,代码行数:25,代码来源:sql_file_info_store.go

示例2: getFileInfo

func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
	if len(utils.Cfg.FileSettings.DriverName) == 0 {
		c.Err = model.NewLocAppError("uploadFile", "api.file.upload_file.storage.app_error", nil, "")
		c.Err.StatusCode = http.StatusNotImplemented
		return
	}

	params := mux.Vars(r)

	channelId := params["channel_id"]
	if len(channelId) != 26 {
		c.SetInvalidParam("getFileInfo", "channel_id")
		return
	}

	userId := params["user_id"]
	if len(userId) != 26 {
		c.SetInvalidParam("getFileInfo", "user_id")
		return
	}

	filename := params["filename"]
	if len(filename) == 0 {
		c.SetInvalidParam("getFileInfo", "filename")
		return
	}

	cchan := Srv.Store.Channel().CheckPermissionsToNoTeam(channelId, c.Session.UserId)

	path := "channels/" + channelId + "/users/" + userId + "/" + filename
	var info *model.FileInfo

	if cached, ok := fileInfoCache.Get(path); ok {
		info = cached.(*model.FileInfo)
	} else {
		err, bytes := getFileData(c.TeamId, channelId, userId, filename)
		if err != nil {
			c.Err = err
			return
		}

		newInfo, err := model.GetInfoForBytes(filename, bytes)
		if err != nil {
			c.Err = err
			return
		} else {
			fileInfoCache.Add(path, newInfo)
			info = newInfo
		}
	}

	if !c.HasPermissionsToChannel(cchan, "getFileInfo") {
		return
	}

	w.Header().Set("Cache-Control", "max-age=2592000, public")

	w.Write([]byte(info.ToJson()))
}
开发者ID:carsonk,项目名称:platform,代码行数:59,代码来源:file.go

示例3: getFileInfo

func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
	if len(utils.Cfg.FileSettings.DriverName) == 0 {
		c.Err = model.NewLocAppError("uploadFile", "api.file.upload_file.storage.app_error", nil, "")
		c.Err.StatusCode = http.StatusNotImplemented
		return
	}

	params := mux.Vars(r)

	channelId := params["channel_id"]
	if len(channelId) != 26 {
		c.SetInvalidParam("getFileInfo", "channel_id")
		return
	}

	userId := params["user_id"]
	if len(userId) != 26 {
		c.SetInvalidParam("getFileInfo", "user_id")
		return
	}

	filename := params["filename"]
	if len(filename) == 0 {
		c.SetInvalidParam("getFileInfo", "filename")
		return
	}

	if !HasPermissionToChannelContext(c, channelId, model.PERMISSION_READ_CHANNEL) {
		return
	}

	path := "teams/" + c.TeamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
	var info *model.FileInfo

	if cached, ok := fileInfoCache.Get(path); ok {
		info = cached.(*model.FileInfo)
	} else {
		fileData := make(chan []byte)
		go readFile(path, fileData)

		newInfo, err := model.GetInfoForBytes(filename, <-fileData)
		if err != nil {
			c.Err = err
			return
		} else {
			fileInfoCache.Add(path, newInfo)
			info = newInfo
		}
	}

	w.Header().Set("Cache-Control", "max-age=2592000, public")

	w.Write([]byte(info.ToJson()))
}
开发者ID:lfbrock,项目名称:platform,代码行数:54,代码来源:file.go

示例4: getInfoForFilename

func getInfoForFilename(post *model.Post, teamId string, filename string) *model.FileInfo {
	// Find the path from the Filename of the form /{channelId}/{userId}/{uid}/{nameWithExtension}
	split := strings.SplitN(filename, "/", 5)
	if len(split) < 5 {
		l4g.Error(utils.T("api.file.migrate_filenames_to_file_infos.unexpected_filename.error"), post.Id, filename)
		return nil
	}

	channelId := split[1]
	userId := split[2]
	oldId := split[3]
	name, _ := url.QueryUnescape(split[4])

	if split[0] != "" || split[1] != post.ChannelId || split[2] != post.UserId || strings.Contains(split[4], "/") {
		l4g.Warn(utils.T("api.file.migrate_filenames_to_file_infos.mismatched_filename.warn"), post.Id, post.ChannelId, post.UserId, filename)
	}

	pathPrefix := fmt.Sprintf("teams/%s/channels/%s/users/%s/%s/", teamId, channelId, userId, oldId)
	path := pathPrefix + name

	// Open the file and populate the fields of the FileInfo
	var info *model.FileInfo
	if data, err := ReadFile(path); err != nil {
		l4g.Error(utils.T("api.file.migrate_filenames_to_file_infos.file_not_found.error"), post.Id, filename, path, err)
		return nil
	} else {
		var err *model.AppError
		info, err = model.GetInfoForBytes(name, data)
		if err != nil {
			l4g.Warn(utils.T("api.file.migrate_filenames_to_file_infos.info.app_error"), post.Id, filename, err)
		}
	}

	// Generate a new ID because with the old system, you could very rarely get multiple posts referencing the same file
	info.Id = model.NewId()
	info.CreatorId = post.UserId
	info.PostId = post.Id
	info.CreateAt = post.CreateAt
	info.UpdateAt = post.UpdateAt
	info.Path = path

	if info.IsImage() {
		nameWithoutExtension := name[:strings.LastIndex(name, ".")]
		info.PreviewPath = pathPrefix + nameWithoutExtension + "_preview.jpg"
		info.ThumbnailPath = pathPrefix + nameWithoutExtension + "_thumb.jpg"
	}

	return info
}
开发者ID:Rudloff,项目名称:platform,代码行数:49,代码来源:file.go


注:本文中的github.com/mattermost/platform/model.FileInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。