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) }
// @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)) } }
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{} }