コード例 #1
0
ファイル: request.go プロジェクト: chenbk85/nephele
func (this ImageRequest) GetChannel(path string) string {
	path = strings.Replace(path, "/", "\\", -1)
	if isNewUri(path) {
		channelCode := util.Substr(path, 1, 2)
		channel := models.Channel{Cat: this.Cat}
		channels, _ := channel.GetAll()
		for k, v := range channels {
			if v == channelCode {
				return k
			}
		}
		return ""
	}
	if isFdfs(path) {
		s := util.Substr(path, 4, len(path)-4)
		i := strings.Index(s, "\\")
		return util.Substr(s, 0, i)
	}
	if isT1(path) {
		s := util.Substr(path, 4, len(path)-4)
		i := strings.Index(s, "\\")
		return util.Substr(s, 0, i)
	}
	s := util.Substr(path, 1, len(path)-4)
	i := strings.Index(s, "\\")
	return util.Substr(s, 0, i)
}
コード例 #2
0
ファイル: channelcontroller.go プロジェクト: chenbk85/nephele
// @router /channel/get/ [get]
func (this *ChannelController) Get() {
	ch := models.Channel{}
	channels, err := ch.GetAll()
	if err.Err != nil {
		this.Ctx.WriteString((err.Err.(error)).Error())
	} else {
		bts, _ := json.Marshal(channels)
		this.Ctx.WriteString(string(bts))
	}
}
コード例 #3
0
ファイル: channelcontroller.go プロジェクト: chenbk85/nephele
// @router /channel/update/ [get]
func (this *ChannelController) Update() {
	name := this.GetString("name")
	code := this.GetString("code")
	if name == "" || code == "" {
		this.Ctx.WriteString("params is't empty")
	}
	channel := models.Channel{Name: name, Code: code}
	err := channel.Update()
	if err != nil {
		this.Ctx.WriteString(err.Error())
	} else {
		this.Ctx.WriteString("success")
	}
}
コード例 #4
0
ファイル: request.go プロジェクト: chenbk85/nephele
func (this ImageRequest) checkSaveRequest(r *request.SaveRequest) util.Error {
	t := "ParamInvalid"
	if r.Channel == "" {
		util.LogEvent(this.Cat, t, "ChannelEmpty", nil)
		return util.Error{IsNormal: true, Err: errors.New("Channel can't be empty"), Type: t}
	}
	if r.FileBytes == nil || len(r.FileBytes) < 1 {
		util.LogEvent(this.Cat, t, util.JoinString(r.Channel, "-FileBytesEmpty"), nil)
		return util.Error{IsNormal: true, Err: errors.New("FileBytes can't be empty"), Type: t}
	}
	channel := models.Channel{Cat: this.Cat}
	channels, err := channel.GetAll()
	if err.Err != nil {
		return err
	}
	_, exists := channels[r.Channel]
	if !exists {
		util.LogEvent(this.Cat, t, util.JoinString(r.Channel, "-NoRegister"), nil)
		return util.Error{IsNormal: true, Err: errors.New(util.JoinString("channel[", r.Channel, "] isn't register!")), Type: t}
	}
	return util.Error{}
}
コード例 #5
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{}
}