Server
August 8, 2023 ยท View on GitHub
API List
| Name | Route | Method | Remark |
|---|---|---|---|
| Navigation Page | / | GET | |
| Login Page | /login/index | GET | |
| User Sign In API | /signin | POST | |
| Source File Server | /source/ | GET | |
| DestPath File Server | /dest/ | GET | |
| File Query API | /query | GET | |
| File Push API | /w/push | POST | |
| PProf API | /manage/pprof | GET | |
| Config API | /manage/config | GET | |
| Report API | /manage/report | GET |
File Query API
Support query source or dest path from File Server.
Request
Method
GET
Parameter
Request field description:
pathquery file path, for examplepath=sourceneed_hashreturn file hash or not,1or0, default is0need_checkpointreturn file checkpoint hash or not,1or0, default is0
Example
Query the source path and return all files and checkpoints hash values.
http://127.0.0.1/query?path=source&need_hash=1&need_checkpoint=1
Response
Parameter
Response field description:
codestatus code,1means success, all status codes see Status Codemessageresponse status descriptiondataresponse datapathfile pathis_diris directory or not,1or0sizefile size of bytes, directory is always0hashreturn file hash value if setneed_hash=1hash_valuesreturn the hash value of the entire file and first chunk and some checkpoints if setneed_checkpoint=1. The details of checkpoints see the use ofcheckpoint_countflagoffsetthe file data to calculate the hash value from zero to offsethashthe file checkpoint hash value
c_timefile creation timea_timefile last access timem_timefile last modify timelink_tolink to the real file
Example
Here is an example response:
{
"code": 1,
"message": "success",
"data": [
{
"path": "go1.18.linux-amd64.tar.gz",
"is_dir": 0,
"size": 141702072,
"hash": "67622d8e307cb055b8ce2c2e03cb58cf",
"hash_values": [
{
"offset": 1048576,
"hash": "29d68359be77cdbe3d59791f0e367012"
},
{
"offset": 13631488,
"hash": "576b3746abb1f71bfbc794c750fb2c19"
},
{
"offset": 27262976,
"hash": "3a720d0a1a1c8abce3bf39cb7bc38507"
},
{
"offset": 40894464,
"hash": "946efd928cda9d0b20e9a74c4ba5db4f"
},
{
"offset": 54525952,
"hash": "eae47693bea9473c5ed859862685e4a7"
},
{
"offset": 68157440,
"hash": "ea700e864621fbee4a50d7b0e70b2e52"
},
{
"offset": 81788928,
"hash": "6c68022d11128ba256fb73a90b5232ef"
},
{
"offset": 95420416,
"hash": "ccfb4397caee4088b90e45d07829f1bf"
},
{
"offset": 109051904,
"hash": "d01e494ca88aa08d8a8a5279948db0b0"
},
{
"offset": 122683392,
"hash": "86bf50e8553674c26e2fbdb4477e44f4"
},
{
"offset": 136314880,
"hash": "51bba2e19d9519babccb0d5f4eedd7c3"
},
{
"offset": 141702072,
"hash": "67622d8e307cb055b8ce2c2e03cb58cf"
}
],
"c_time": 1649431872,
"a_time": 1649431873,
"m_time": 1647397031,
"link_to": ""
},
{
"path": "hello_gofs.txt",
"is_dir": 0,
"size": 11,
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3",
"hash_values": [
{
"offset": 11,
"hash": "5eb63bbbe01eeed093cb22bb8f5acdc3"
}
],
"c_time": 1649431542,
"a_time": 1649434237,
"m_time": 1649434237,
"link_to": ""
},
{
"path": "resource",
"is_dir": 1,
"size": 0,
"hash": "",
"hash_values": null,
"c_time": 1649431669,
"a_time": 1649431898,
"m_time": 1649431898,
"link_to": ""
}
]
}
File Push API
Push the file changes to the Remote Push Server.
Request
Method
POST
Parameter
Request field description:
push_datathe request data of push api, contains basic push file info and chunk info etcactionthe action of file change, Create(1) Write(2) Remove(3) Rename(4) Chmod(5) Symlink(6)push_actionthe file upload action, CompareFile(1) CompareChunk(2) CompareFileAndChunk(3) Write(4) Truncate(5)file_infobasic push file infopathfile pathis_diris directory or not,1or0sizefile size of bytes, directory is always0hashfile hash valuec_timefile creation timea_timefile last access timem_timefile last modify timelink_tolink to the real file
chunkoffsetthe offset relative to the origin of the filesizefile chunk size of bytes, directory is always0hashfile chunk hash value
force_checksumif the file size and file modification time of the source file is equal to the destination file and force_checksum isfalse, then ignore the current file transfer, default isfalse
up_filethe field name of upload file or chunk
Example
Upload a file to the remote push server.
POST https://127.0.0.1/w/push HTTP/1.1
Host: 127.0.0.1
User-Agent: Go-http-client/1.1
Content-Length: 674
Content-Type: multipart/form-data; boundary=d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1
Cookie: session_id=MTY1MTY4MTkxNXxOd3dBTkVkQlZFMUNTVk5UTmsxS00wNVlTbEJMTnpJM1RFWklVVmhQUTBsTlFWaEZUbFZhVjB4VU5UYzJTazFNTWpSRFJFWlpUVUU9fMFwFk6SpF9vVsNcwNe6LnmxVCgshxv-ubZzZbTTDgnq
Accept-Encoding: gzip
--d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1
Content-Disposition: form-data; name="push_data"
{"action":2,"push_action":4,"file_info":{"path":"hello_gofs.txt","is_dir":0,"size":5,"hash":"5d41402abc4b2a76b9719d911017c592","hash_values":null,"c_time":1651681421,"a_time":1651681421,"m_time":1651681421,"link_to":""},"chunk":{"offset":0,"hash":"5d41402abc4b2a76b9719d911017c592","size":5},"force_checksum":false}
--d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1
Content-Disposition: form-data; name="up_file"; filename="hello_gofs.txt"
Content-Type: application/octet-stream
hello
--d9e3eb63103de1c2698b0675a70567e47bed1b06c71ff9e26199967312d1--
Response
Parameter
Response field description:
codestatus code,1means success, all status codes see Status Codemessageresponse status descriptiondataresponse data
Example
Here is an example response:
{
"code": 1,
"message": "success",
"data": null
}
Report API
Query the report data if you enable the manage and report flags.
Request
Method
GET
Example
https://127.0.0.1/manage/report
Response
Parameter
Response field description:
codestatus code,1means success, all status codes see Status Codemessageresponse status descriptiondataresponse datacurrent_timereturns the current server timestart_timereturns the server start timeup_timereturns the server up timepidreturns the process id of the callerppidreturns the process id of the caller's parenthostnamereturns the host name reported by the kernelgo_osis the running program's operating system targetgo_archis the running program's architecture targetgo_versionreturns the Go tree's version stringversionreturns the version info of the gofscommitreturns last commit hash value of the gofsonlinereturns the client connection info that is onlineaddrthe client connection addressusernamethe username of clientpermthe permission of clientconnect_timethe connected time of clientdisconnect_timethe disconnected time of clientlife_timethe lifetime of a client, it is0salways that if the client is online
offlinereturns the client connection info that is offline, full fields seeonlineeventsreturns some latest file change eventsnamethe path of file changeopthe operation of file changetimethe time of file change
event_statreturns the statistical data of file change eventsapi_statreturns the statistical data of api access infoaccess_countall the api access countvisitor_statthe statistical data of visitors
Example
Here is an example response:
{
"code": 1,
"message": "success",
"data": {
"current_time": "2022-03-28 01:36:31",
"start_time": "2022-03-28 01:00:00",
"up_time": "36m31s",
"pid": 94032,
"ppid": 9268,
"hostname": "no-src",
"go_os": "windows",
"go_arch": "amd64",
"go_version": "go1.18",
"version": "v0.4.0",
"commit": "753f90b3dd1454ca4c87f43b1bb5e6aaabbd7689",
"online": {
"127.0.0.1:11993": {
"addr": "127.0.0.1:11993",
"username": "698d51a19d8a121c",
"perm": "rwx",
"connect_time": "2022-03-28 01:10:11",
"disconnect_time": "1970-01-01 08:00:00",
"life_time": "0s"
}
},
"offline": [
{
"addr": "127.0.0.1:11887",
"username": "698d51a19d8a121c",
"perm": "rwx",
"connect_time": "2022-03-28 01:08:46",
"disconnect_time": "2022-03-28 01:10:06",
"life_time": "1m20s"
}
],
"events": [
{
"name": "C:\\workspace\\hello_gofs.txt",
"op": "WRITE",
"time": "2022-03-28 01:10:01"
}
],
"event_stat": {
"WRITE": 1
},
"api_stat": {
"access_count": 14,
"visitor_stat": {
"127.0.0.1": 11,
"192.168.0.106": 3
}
}
}
}
Status Code
All common response status code enums below.
0Unknown1Success-1Fail-2Unauthorized-3NotFound-4NoPermission-5ServerError-6AccessDeny-7NotModified-8ChunkNotModified-9Modified-10ChunkModified