muharihar / file-finder
Laravel 本地文件查找包
0.1.2
2018-10-14 14:53 UTC
Requires
- php: >=7.0.0
- laravel/framework: >=5.6
Requires (Dev)
- laravel/dusk: ^4.0
- phpunit/phpunit: ^7.0
This package is not auto-updated.
Last update: 2024-09-23 20:51:50 UTC
README
Laravel Local File Finder Package 是一个简单的 Laravel 包,允许通过内容查找文件(目前仅支持 .txt 文件)。
在线演示
可用功能
- 列出默认存储目录和文件。
- 按名称搜索文件和目录。
- 按内容搜索文件。
REST API 功能
- [Swagger UI] (http://host:port/file-finder/api/docs)
安装
- 创建 Laravel 项目
$ composer create-project --prefer-dist laravel/laravel laravel_file_finder_5.6_test "5.6.*"
- 添加 FileFinder 包
$ cd laravel_file_finder_5.6_test
$ composer require muharihar/file-finder
- 发布资产和默认数据样本
$ php artisan vendor:publish --tag=public --force
- 将 FileFinder 服务提供者添加到 Laravel 应用配置 (config/app.php)
/* * Package Service Providers... */ Muharihar\FileFinder\ServiceProviders\FileFinderServiceProvider::class,
- 运行应用
$ php artisan serve
- 打开 Swagger UI 测试功能: http://127.0.0.1:8000/file-finder/api/docs
通过 CURL 测试
1. 列出默认存储目录和文件。
命令
$ curl -v -X GET "https://:8000/file-finder/api/v1.0/default/list-dir-and-files" -H "accept: application/json"
示例结果: sampleResponse
2. 按名称搜索文件和目录。
命令
$ curl -X GET "https://:8000/file-finder/api/v1.0/search/by-name?s=b" -H "accept: application/json"
示例结果
{
"searchKey": "b",
"results": [
{
"idx": 2,
"isDir": true,
"shortPath": "public/file-finder/folder_animals/folder_birds",
"extension": "",
"fileSize": 0,
"parentPath": "public/file-finder/folder_animals"
},
{
"idx": 12,
"isDir": true,
"shortPath": "public/file-finder/folder_fruits/folder_berries",
"extension": "",
"fileSize": 0,
"parentPath": "public/file-finder/folder_fruits"
},
{
"idx": 13,
"isDir": false,
"shortPath": "public/file-finder/folder_fruits/folder_berries/file_berries_list.txt",
"extension": "txt",
"fileSize": 44,
"parentPath": "public/file-finder/folder_fruits/folder_berries"
},
{
"idx": 26,
"isDir": false,
"shortPath": "public/file-finder/folder_geolocations/folder_cities/file_bg.txt",
"extension": "txt",
"fileSize": 633,
"parentPath": "public/file-finder/folder_geolocations/folder_cities"
}
],
"resultCount": 4
}
3. 按内容搜索文件。
命令
$ curl -X GET "https://:8000/file-finder/api/v1.0/search/by-content?s=Obama" -H "accept: application/json"
示例结果
{
"searchKey": "Obama",
"results": [
{
"idx": 41,
"isDir": false,
"shortPath": "public/file-finder/folder_peoples/folder_presidents/file_us.txt",
"extension": "txt",
"fileSize": 6713,
"parentPath": "public/file-finder/folder_peoples/folder_presidents",
"info": {
"firstPos": 6580,
"firstStr": "...Obama,http://en.wikipedia.org/wiki/Barack_Obama,20"
}
}
],
"resultCount": 1
}
