Пример #1
0
func (this ImageRequest) getStorageBySource(path string, isSource bool) (Storage, util.Error) {
	path = strings.Replace(path, "/", "\\", -1)
	var (
		storagePath string
		storageType string
	)
	var storage Storage
	if isNewUri(path) {
		imagename := util.Substr(path, 1, NEWIMAGENAMELENGTH)
		imgIndex := models.ImageIndex{Cat: this.Cat}
		if e := imgIndex.Parse(imagename); e.Err != nil {
			return nil, e
		}
		storagePath = imgIndex.StoragePath

		storageType = imgIndex.StorageType
		storage = CreateStorage(storagePath, storageType, this.Cat)
		if storage == nil {
			util.LogErrorEvent(this.Cat, ERRORTYPE_STORAGETYPENOSUPPORTE, util.JoinString("Can't supporte storagetype[", storageType, "]"))
			return nil, util.Error{IsNormal: false, Err: errors.New(util.JoinString("Can't supporte storagetype[", storageType, "]")), Type: ERRORTYPE_STORAGETYPENOSUPPORTE}
		}
	} else {
		storageType = STORAGETYPE_NFS
		if isFdfs(path) {
			storageType = STORAGETYPE_FDFS
		}
		storage = CreateStorage(path, storageType, this.Cat)
		if e := storage.ConvertFilePath(isSource); e.Err != nil {
			return nil, e
		}
	}
	return storage, util.Error{}
}
Пример #2
0
// @router /image/delete/:uri [get]
func (c *ImageDeleteController) Get() {
	var (
		st string
		sp string
	)
	uri := c.GetString(":uri")
	var ii models.ImageIndex = models.ImageIndex{}
	err := ii.Parse(uri)
	if err.Type != "" {
		return
	}

	st, sp = ii.StorageType, ii.StoragePath
	if st == EmptyString || sp == EmptyString {
		return
	}

	switch st {
	case "fdfs":

	case "nfs":

	default:
		//ErrIllegalStorageType
		return
	}
	println("delete record from MySQL")
}
Пример #3
0
func (this ImageRequest) Save(r *request.SaveRequest) (response.SaveResponse, util.Error) {
	r.TargetFormat = strings.ToLower(r.TargetFormat)
	r.Channel = strings.ToLower(r.Channel)
	util.LogEvent(this.Cat, "Save", r.Channel, nil)

	this.checkPlanID(r)
	if err := this.checkSaveRequest(r); err.Err != nil {
		return response.SaveResponse{}, err
	}
	if err := this.checkSaveCheckItem(r); err.Err != nil {
		return response.SaveResponse{}, err
	}
	storage, storageType := NewStorage(this.Cat)
	path, e := storage.Upload(r.FileBytes, r.TargetFormat)
	if e.Err != nil {
		return response.SaveResponse{}, e
	}
	tableZone := sharding()
	channel := models.Channel{Cat: this.Cat}
	imgIndex := models.ImageIndex{ChannelCode: channel.GetChannelCode(r.Channel), StoragePath: path, StorageType: storageType, TableZone: tableZone, Cat: this.Cat}
	plan := ""
	if r.Process.AnyTypes != nil && len(r.Process.AnyTypes) > 0 {
		bts, err := r.Process.MarshalJSON()
		if err != nil {
			util.LogErrorEvent(this.Cat, ERRORTYPE_MARSHALJSON, err.Error())
			return response.SaveResponse{}, util.Error{IsNormal: false, Err: err, Type: ERRORTYPE_MARSHALJSON}
		}
		plan = string(bts)
	}

	if e := imgIndex.SaveToDB(plan); e.Err != nil {
		return response.SaveResponse{}, e
	}
	uri := imgIndex.GetImageName()
	return response.SaveResponse{CheckPass: true, OriginalPath: uri, TargetPath: uri}, util.Error{}
}
Пример #4
0
func (this ImageRequest) Delete(r *request.DeleteRequest) (response.DeleteResponse, util.Error) {
	storage, e := this.getStorage(r.FilePath)
	if e.Err != nil {
		return response.DeleteResponse{}, e
	}
	util.LogEvent(this.Cat, "Delete", this.GetChannel(r.FilePath), map[string]string{"uri": r.FilePath, "IsDeleteAll": strconv.FormatBool(r.IsDeleteAll)})

	if isNewUri(r.FilePath) {
		imgIndex := models.ImageIndex{Cat: this.Cat}
		e = imgIndex.ParseName(r.FilePath)
		if e.Err != nil {
			return response.DeleteResponse{}, e
		}
		e = imgIndex.Delete()
		if e.Err != nil {
			return response.DeleteResponse{}, e
		}
	}
	e = storage.Delete(r.IsDeleteAll)
	if e.Err != nil {
		return response.DeleteResponse{}, e
	}
	return response.DeleteResponse{}, util.Error{}
}