예제 #1
0
파일: request.go 프로젝트: chenbk85/nephele
func (this ImageRequest) checkPlanID(r *request.SaveRequest) {
	if len(r.PlanID) > 0 {
		if r.PlanID == "tg_o1.5" || r.PlanID == "tg_n2.0" {
			r.Channel = "tg"
		}
		if r.PlanID == "tg_test1" {
			r.Channel = "test"
		}
		r.OriginalFormat = jpg
		r.TargetFormat = jpg
		r.Process.AnyTypes = make([]request.AnyType, 0)
	}
}
예제 #2
0
파일: request.go 프로젝트: chenbk85/nephele
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{}
}