コード例 #1
0
ファイル: eazyphotod.go プロジェクト: sergeyfast/eazyphotod
func Main() {
	var err error
	flag.Parse()
	err = gcfg.ReadFileInto(&cfg, *configFile)
	logFatal(err)

	setRootDir()
	logFatal(pingBtSync())

	// open db
	logFatal(pingModel())
	defer model.Close()

	// join all photos
	Albums, err = model.Albums() // TODO Albums as Storage
	logFatal(err)
	photos, err := model.Photos()
	logFatal(err)
	model.JoinPhotos(Albums, photos)

	// Queue Albums
	if wds, err := model.PushToBtSync(Albums, bstClient); err != nil {
		logFatal(err)
	} else {
		for _, d := range wds {
			if err = WatchDir(d); err != nil {
				logFatal(err)
			}
		}
	}

	//	// start goroutines
	go RunFsSync(Albums)
	go WatcherLoop()
	go Dispatch()
	go DispatchFsSync()

	// Start Server
	listenAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
	glog.Infof("Starting eazyphotod at %s\n", listenAddress)
	http.HandleFunc("/update/album-meta", updateMetaHandler)
	http.HandleFunc("/update/albums", updateAlbumsHandler)
	err = http.ListenAndServe(listenAddress, nil)
	logFatal(err)
}
コード例 #2
0
ファイル: sync.go プロジェクト: rubyfox/eazyphotod
// Reload New Albums
func updateAlbums() error {
	albums, err := model.Albums()
	if err != nil {
		return err
	}

	// Filter New albums
	newAlbums := make(model.AlbumList)
	for _, a := range albums {
		if a.StatusId == model.StatusInQueue {
			newAlbums[a.AlbumId] = a
		}
	}

	if len(newAlbums) == 0 {
		return nil
	}

	// Queue Albums
	if wds, err := model.PushToBtSync(newAlbums, bstClient); err != nil {
		return err
	} else {
		for _, d := range wds {
			if err = WatchDir(d); err != nil {
				return err
			}
		}
	}

	// Update Albums Storage
	for _, a := range newAlbums {
		if curAl, ok := Albums[a.AlbumId]; ok {
			a.Photos = curAl.Photos
		}

		Albums[a.AlbumId] = a
	}

	return nil
}