예제 #1
0
func (this *ProcChainBuilder) Build(params map[string]string) (*proc.ProcessorChain, *buildError) {
	procChain := &proc.ProcessorChain{Chain: make([]proc.ImageProcessor, 0, 10)}

	sourceType, channel, path := ParseUri(params[":1"])
	//_, channel, _ := ParseUri(params[":1"])
	sequences, e := data.GetSequenceofoperation(channel)
	if e != nil {
		return nil, &buildError{e, "UrlSequenceCmdError"}
	}
	for _, t := range sequences {
		switch t {
		case CmdStrip:
			stripProcessor, e := this.getStripProcessor(channel, params)
			if e != nil {
				return nil, &buildError{e, "UrlStripCmdError"}
			}
			procChain.Chain = append(procChain.Chain, stripProcessor)
			log.Debug("add strip processor")
		case CmdResize:
			resizeProcessor, e := this.getResizeProcessor(channel, params)
			if e != nil {
				return nil, &buildError{e, "UrlResizeCmdError"}
			}
			procChain.Chain = append(procChain.Chain, resizeProcessor)
			log.Debug("add resize processor")
		case CmdQuality:
			qualityProcessor, e := this.getQualityProcessor(channel, params)
			if e != nil {
				return nil, &buildError{e, "UrlQualityCmdError"}
			}
			if qualityProcessor != nil {
				procChain.Chain = append(procChain.Chain, qualityProcessor)
				log.Debug("add quality processor")
			}
		case CmdRotate:
			rotateProcessor, e := this.getRotateProcessor(channel, params)
			if e != nil {
				return nil, &buildError{e, "UrlRotateCmdError"}
			}
			if rotateProcessor != nil {
				procChain.Chain = append(procChain.Chain, rotateProcessor)
				log.Debug("add rotate processor")
			}
		case CmdWaterMark:
			waterMarkProcessors, e := this.getWaterMarkProcessors(sourceType, channel, path, params)
			if e != nil {
				return nil, &buildError{e, "UrlWaterMarkCmdError"}
			}
			if waterMarkProcessors != nil {
				for _, p := range waterMarkProcessors {
					if p != nil {
						procChain.Chain = append(procChain.Chain, p)
					}
				}
			}
		case CmdFormat:
			formatProcessor, e := this.getFormatProcessor(channel, params)
			if e != nil {
				return nil, &buildError{e, "UrlFormatCmdError"}
			}
			if formatProcessor != nil {
				procChain.Chain = append(procChain.Chain, formatProcessor)
				log.Debug("add format processor")
			}
		case CmdDigitalWatermark:
			dwmProcessor, e := this.getDigitalWatermarkProcessor(channel, params)
			if e != nil {
				return nil, &buildError{e, "UrlDigitalWatermarkCmdError"}
			}
			if dwmProcessor != nil {
				procChain.Chain = append(procChain.Chain, dwmProcessor)
				log.Debug("add digital watermark processor")
			}
		}
	}
	return procChain, nil
}
예제 #2
0
func (this *ProcChainBuilder) Build(params map[string]string) (*proc.ProcessorChain, error) {
	procChain := &proc.ProcessorChain{Chain: make([]proc.ImageProcessor, 0, 5)}

	sourceType, channel, path := ParseUri(params[":1"])
	sequences, e := data.GetSequenceofoperation(channel)
	if e != nil {
		return nil, e
	}
	for _, t := range sequences {
		switch t {
		case "s":
			stripProcessor, e := this.getStripProcessor(channel, params)
			if e != nil {
				return nil, e
			}
			procChain.Chain = append(procChain.Chain, stripProcessor)
			l4g.Debug("add strip processor")
		case "resize":
			resizeProcessor, e := this.getResizeProcessor(channel, params)
			if e != nil {
				return nil, e
			}
			procChain.Chain = append(procChain.Chain, resizeProcessor)
			l4g.Debug("add resize processor")
		case "q":
			qualityProcessor, e := this.getQualityProcessor(channel, params)
			if e != nil {
				return nil, e
			}
			if qualityProcessor != nil {
				procChain.Chain = append(procChain.Chain, qualityProcessor)
				l4g.Debug("add quality processor")
			}
		case "rotate":
			rotateProcessor, e := this.getRotateProcessor(channel, params)
			if e != nil {
				return nil, e
			}
			if rotateProcessor != nil {
				procChain.Chain = append(procChain.Chain, rotateProcessor)
				l4g.Debug("add rotate processor")
			}
		case "m":
			waterMarkProcessors, e := this.getWaterMarkProcessors(sourceType, channel, path, params)
			if e != nil {
				return nil, e
			}
			if waterMarkProcessors != nil {
				for _, p := range waterMarkProcessors {
					if p != nil {
						procChain.Chain = append(procChain.Chain, p)
					}
				}
			}
		case "f":
			formatProcessor, e := this.getFormatProcessor(channel, params)
			if e != nil {
				return nil, e
			}
			if formatProcessor != nil {
				procChain.Chain = append(procChain.Chain, formatProcessor)
				l4g.Debug("add format processor")
			}
		}
	}
	return procChain, nil
}