Пример #1
0
func Test_encodeEntities_ShouldEncodeEntitiesCorrectly(t *testing.T) {
	exp := explorer.New("dummy root")
	encoder, _ := crypto.NewEncoder("1234567890123456")
	controller := NewScanController(encoder, exp)
	files := []explorer.File{
		explorer.File{
			Path: "file path",
		},
	}
	directories := []explorer.Directory{
		explorer.Directory{
			Path: "directory path",
		},
	}

	files, directories = controller.encodeEntities(files, directories)

	encodedFilePath := files[0].Path
	encodedDirectoryPath := directories[0].Path

	decodedFilePath, _ := encoder.Decrypt(encodedFilePath)
	decodedDirectoryPath, _ := encoder.Decrypt(encodedDirectoryPath)

	assert.Equal(t, "file path", decodedFilePath)
	assert.Equal(t, "directory path", decodedDirectoryPath)
}
Пример #2
0
func (server *Server) registerRoutes(router *mux.Router) {
	key := server.Config.Key
	encoder, err := crypto.NewEncoder(key)
	if err != nil {
		panic(err)
	}

	scanDirController := controller.NewScanController(
		encoder,
		explorer.New(server.Config.RootDir),
	)

	router.PathPrefix("/css/").Handler(
		http.StripPrefix("/css/", http.FileServer(http.Dir(cssDir))))
	router.PathPrefix("/img/").Handler(
		http.StripPrefix("/img/", http.FileServer(http.Dir(imgDir))))

	router.HandleFunc("/", scanDirController.HomeHandler)
	router.HandleFunc("/scan/{dir}/", scanDirController.ScanHandler)
	router.HandleFunc("/search/", scanDirController.SearchHandler)
}