Пример #1
0
func (m *Manager) NewSearchWithStrDict(dict map[string]string) (string, bool) {
	datas := []dataInfo{}
	strs := ""

	for k, v := range dict {
		strs += k + "+"
		pyList := pinyin.HansToPinyin(v)
		if len(pyList) == 1 && pyList[0] == v {
			info := dataInfo{v, k}
			datas = append(datas, info)
			continue
		}

		for _, l := range pyList {
			info := dataInfo{l, k}
			datas = append(datas, info)
		}
		info := dataInfo{v, k}
		datas = append(datas, info)
	}

	md5Str, ok := dutils.SumStrMd5(strs)
	if !ok {
		logger.Warning("Sum MD5 Failed")
		return "", false
	}

	cachePath, ok1 := getCachePath()
	if !ok1 {
		logger.Warning("Get Cache Path Failed")
		return "", false
	}

	filename := path.Join(cachePath, md5Str)
	m.writeStart = true
	m.writeEnd = make(chan bool)
	go func() {
		writeDatasToFile(&datas, filename)
		m.writeEnd <- true
		m.writeStart = false
	}()

	return md5Str, true
}
Пример #2
0
func GetThumbnail(seed, uri string) string {
	if !isThumbSeedValid(seed) {
		return ""
	}

	src := dutils.DecodeURI(uri)
	dir := path.Join(os.Getenv("HOME"), userThumbFileDir)
	md5Str, _ := dutils.SumStrMd5(seed + src)
	dest := path.Join(dir, md5Str+".png")
	if dutils.IsFileExist(dest) {
		//return dutils.EncodeURI(dest, dutils.SCHEME_FILE)
		return dest
	}

	dest = path.Join(systemThumbFileDir, md5Str+".png")
	if dutils.IsFileExist(dest) {
		//return dutils.EncodeURI(dest, dutils.SCHEME_FILE)
		return dest
	}

	return ""
}
Пример #3
0
// strToUuid convert any given string to md5, and then to uuid, for
// example, a device address string "00:12:34:56:ab:cd" will be
// converted to "1d417dad-8a98-fb90-e9df-016bd616d7dd"
func strToUuid(str string) (uuid string) {
	md5, _ := utils.SumStrMd5(str)
	return doStrToUuid(md5)
}