### Install Go Dependencies Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Installs or updates Go module dependencies. Run this command to ensure all necessary packages are downloaded. ```bash # Install dependencies go mod tidy ``` -------------------------------- ### Build the Project Source: https://github.com/sheltonzhu/115driver/blob/main/QWEN.md Commands to clone the repository, install dependencies, and build the main package and MCP server. ```bash # Clone the repository git clone https://github.com/SheltonZhu/115driver.git cd 115driver # Install dependencies go mod tidy # Build the main package go build ./cmd/... # Build the MCP server go build -o mcp-server ./mcp/main.go ``` -------------------------------- ### Install 115driver Go Library Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Use this command to add the 115driver library to your Go project. ```bash go get github.com/SheltonZhu/115driver ``` -------------------------------- ### Initialize the 115driver Client Source: https://github.com/sheltonzhu/115driver/blob/main/QWEN.md Example of importing the driver package and initializing a client with user credentials to perform a login check. ```go import "github.com/SheltonZhu/115driver/pkg/driver" // Initialize client with credentials cr := &driver.Credential{ UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx", } client := driver.Default().ImportCredential(cr) if err := client.LoginCheck(); err != nil { log.Fatalf("login error: %s", err) } ``` -------------------------------- ### Client Configuration with Options Pattern Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Demonstrates configuring the 115driver client using the Options pattern. This allows for flexible setup of user agent and debug mode. ```go client := driver.New( driver.UA(driver.UA115Browser), driver.WithDebug(), ).ImportCredential(cr) ``` -------------------------------- ### List Directory Request Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md Example JSON-RPC request to list files and directories in the root directory. ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "listDirectory", "arguments": { "dir_id": "0" } } } ``` -------------------------------- ### List Directory Response Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md Example JSON-RPC response for a directory listing, containing file and directory information. ```json { "jsonrpc": "2.0", "id": "1", "result": { "content": [ { "type": "text", "text": "[{"Id":"12345","Name":"Documents","Size":0,"Type":1,"CreateTime":1234567890},{"Id":"67890","Name":"image.jpg","Size":1024,"Type":0,"CreateTime":1234567891}]" } ] } } ``` -------------------------------- ### Run MCP Server with Cookie Authentication Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Starts the MCP server, requiring authentication via a cookie string. Replace 'xxx' with your actual cookie values. ```bash # The MCP server requires cookie authentication ./mcp/115driver-mcp-server --cookie="UID=xxx;CID=xxx;SEID=xxx;KID=xxx" ``` -------------------------------- ### Get File/Directory Statistics Source: https://context7.com/sheltonzhu/115driver/llms.txt Retrieve detailed statistical information about a file or directory. Requires authentication and a file ID. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) fileID := "1234567890" // Get file statistics stat, err := client.Stat(fileID) if err != nil { log.Fatalf("Stat failed: %v", err) } log.Printf("Name: %s", stat.Name) log.Printf("Is Directory: %v", stat.IsDirectory) log.Printf("PickCode: %s", stat.PickCode) log.Printf("SHA1: %s", stat.Sha1) log.Printf("Created: %v", stat.CreateTime) log.Printf("Updated: %v", stat.UpdateTime) if stat.IsDirectory { log.Printf("File Count: %d", stat.FileCount) log.Printf("Directory Count: %d", stat.DirCount) } // Print parent path for _, parent := range stat.Parents { log.Printf("Parent: %s (ID: %s)", parent.Name, parent.ID) } // Get file info by ID file, err := client.GetFile(fileID) if err != nil { log.Fatalf("GetFile failed: %v", err) } log.Printf("File: %s, Size: %d, Labels: %v", file.Name, file.Size, file.Labels) } ``` -------------------------------- ### Search Request Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md Example JSON-RPC request to search for documents containing the word 'report', limiting results to 10. ```json { "jsonrpc": "2.0", "id": "2", "method": "tools/call", "params": { "name": "search", "arguments": { "search_value": "report", "limit": 10, "type": 2 } } } ``` -------------------------------- ### MCP Tool Request Example: Search Source: https://context7.com/sheltonzhu/115driver/llms.txt A JSON-RPC 2.0 request to the MCP server to perform a search. Includes search value, limit, and type of search. ```json { "jsonrpc": "2.0", "id": "2", "method": "tools/call", "params": { "name": "search", "arguments": { "search_value": "document", "limit": 10, "type": 2 } } } ``` -------------------------------- ### MCP Tool Request Example: List Directory Source: https://context7.com/sheltonzhu/115driver/llms.txt A JSON-RPC 2.0 request to the MCP server to list directory contents. Specifies the directory ID and a limit for the results. ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "listDirectory", "arguments": { "dir_id": "0", "limit": 20 } } } ``` -------------------------------- ### Get Share Snapshot with Pagination in Go Source: https://context7.com/sheltonzhu/115driver/llms.txt Retrieves a paginated snapshot of a shared directory using a share code and receive code. Ensure credentials are imported before calling. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) shareCode := "sw12abc" receiveCode := "1234" // Get share snapshot with pagination snap, err := client.GetShareSnap( shareCode, receiveCode, "", // root directory of share driver.QueryLimit(50), driver.QueryOffset(0), ) if err != nil { log.Fatalf("Failed to get share snap: %v", err) } log.Printf("Share info - Count: %d", snap.Count) for _, file := range snap.List { log.Printf("Shared: %s (Size: %d)", file.Name, file.Size) } } ``` -------------------------------- ### MCP Tool Request Example: Add Offline Task Source: https://context7.com/sheltonzhu/115driver/llms.txt A JSON-RPC 2.0 request to the MCP server to add an offline download task. Provides URIs to download and the save directory ID. ```json { "jsonrpc": "2.0", "id": "3", "method": "tools/call", "params": { "name": "addOfflineTaskURIs", "arguments": { "uris": ["https://example.com/file.zip"], "save_dir_id": "0" } } } ``` -------------------------------- ### Get Directory ID by Path Source: https://context7.com/sheltonzhu/115driver/llms.txt Converts a directory path string into its corresponding category ID (CID). Useful for referencing directories in other API calls. Requires authentication. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // Get directory ID from path dirInfo, err := client.DirName2CID("Documents/Projects/2024") if err != nil { log.Fatalf("Failed to get directory ID: %v", err) } log.Printf("Directory ID: %s, Name: %s", dirInfo.CategoryID, dirInfo.Name) } ``` -------------------------------- ### Basic Usage: Initialize Client and Login Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Demonstrates how to create a client using credentials from a cookie string or manually, and then check the login status. ```go package main import ( "github.com/SheltonZhu/115driver/pkg/driver" "log" ) func main() { // Create credentials from cookie string cr, err := driver.CredentialFromCookie("your_cookie_string") if err != nil { log.Fatalf("Failed to create credential: %v", err) } // Or create manually cr := &driver.Credential{ UID: "your_uid", CID: "your_cid", SEID: "your_seid", KID: "your_kid", } // Create client with credentials client := driver.Default().ImportCredential(cr) // Check login status if err := client.LoginCheck(); err != nil { log.Fatalf("Login failed: %v", err) } log.Println("Successfully logged in!") } ``` -------------------------------- ### Server Startup Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md Instructions on how to build and run the MCP server. ```APIDOC ## Server Startup To build the MCP server, run: ```bash go build -o mcp-server mcp/main.go ``` Then, run the server with your 115 cookies: ```bash ./mcp-server --cookie="UID=your_uid;CID=your_cid;SEID=your_seid" ``` The server will listen on stdin/stdout for MCP requests. ``` -------------------------------- ### Initialize 115driver Client Source: https://context7.com/sheltonzhu/115driver/llms.txt Create a new client instance using default settings or custom configurations like proxy and debug mode. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { // Create default client client := driver.Default() // Create client with custom options client = driver.New( driver.UA("Custom-UserAgent/1.0"), driver.WithDebug(), driver.WithProxy("http://127.0.0.1:8080"), driver.InsecureSkipVerify(true), ) log.Println("Client initialized successfully") } ``` -------------------------------- ### Build MCP Server Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md Build the MCP server executable. Ensure you are in the correct project directory. ```bash go build -o mcp-server mcp/main.go ``` -------------------------------- ### Upload a File using Rapid Upload Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Demonstrates how to upload a local file to 115 cloud storage using the rapid upload feature, which utilizes file hashing for efficiency. Ensure the file exists and you have valid credentials. ```go package main import ( "github.com/SheltonZhu/115driver/pkg/driver" "log" "os" ) func main() { client := driver.Default() // Create credentials and login cr, _ := driver.CredentialFromCookie("your_cookie") client = client.ImportCredential(cr) client.LoginCheck() // Open the file file, err := os.Open("/path/to/local/file.zip") if err != nil { log.Fatalf("Failed to open file: %v", err) } defer file.Close() // Get file info fileInfo, err := file.Stat() if err != nil { log.Fatalf("Failed to get file info: %v", err) } // Rapid upload (fast upload using file hash) uploadID, err := client.RapidUploadOrByOSS( "0", // parent directory ID (0 for root) fileInfo.Name(), fileInfo.Size(), file, ) if err != nil { log.Fatalf("Upload failed: %v", err) } log.Printf("Upload started, init response: %+v", uploadID) } ``` -------------------------------- ### Download a File using Pickcode Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Shows how to download a file from 115 cloud storage using its pickcode and save it locally. Ensure you have valid credentials and the pickcode. ```go package main import ( "github.com/SheltonZhu/115driver/pkg/driver" "io" "log" "os" ) func main() { client := driver.Default() // Create credentials and login cr, _ := driver.CredentialFromCookie("your_cookie") client = client.ImportCredential(cr) client.LoginCheck() // Download a file using pickcode pickCode := "abc123" downloadInfo, err := client.Download(pickCode) if err != nil { log.Fatalf("Download failed: %v", err) } // Save the file outFile, err := os.Create("/path/to/save/file.zip") if err != nil { log.Fatalf("Failed to create file: %v", err) } defer outFile.Close() fileReader, err := downloadInfo.Get() if err != nil { log.Fatalf("Failed to get file reader: %v", err) } defer fileReader.Close() if _, err := io.Copy(outFile, fileReader); err != nil { log.Fatalf("Failed to save file: %v", err) } log.Println("Download completed!") } ``` -------------------------------- ### Build and Run MCP Server in Bash Source: https://context7.com/sheltonzhu/115driver/llms.txt Builds the MCP server executable and runs it with cookie authentication. Replace placeholders with actual cookie values. ```bash # Build the MCP server go build -o mcp-server mcp/main.go # Run with cookie authentication ./mcp-server --cookie="UID=xxx;CID=xxx;SEID=xxx;KID=xxx" ``` -------------------------------- ### Run the MCP Server Source: https://github.com/sheltonzhu/115driver/blob/main/QWEN.md Execute the MCP server binary using cookie-based authentication credentials. ```bash ./mcp-server --cookie="UID=your_uid;CID=your_cid;SEID=your_seid;KID=your_kid" ``` -------------------------------- ### List Directory Contents with Pagination Source: https://context7.com/sheltonzhu/115driver/llms.txt Lists files and directories in a specified directory, supporting pagination and custom limits. Requires authentication with user credentials. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // List root directory (ID "0") files, err := client.List("0") if err != nil { log.Fatalf("List failed: %v", err) } for _, file := range *files { fileType := "File" if file.IsDirectory { fileType = "Directory" } log.Printf("[%s] %s - ID: %s, Size: %d bytes, PickCode: %s", fileType, file.Name, file.FileID, file.Size, file.PickCode) } // List with pagination using ListPage pagedFiles, err := client.ListPage("0", 0, 20) // offset=0, limit=20 if err != nil { log.Fatalf("ListPage failed: %v", err) } log.Printf("Retrieved %d items", len(*pagedFiles)) // List with custom limit limitedFiles, err := client.ListWithLimit("0", 100) if err != nil { log.Fatalf("ListWithLimit failed: %v", err) } log.Printf("Total items: %d", len(*limitedFiles)) } ``` -------------------------------- ### Create Directory Source: https://context7.com/sheltonzhu/115driver/llms.txt Creates a new directory within a specified parent directory. Returns the new directory's ID. Requires authentication. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // Create directory in root ("0") dirID, err := client.Mkdir("0", "My New Folder") if err != nil { log.Fatalf("Failed to create directory: %v", err) } log.Printf("Created directory with ID: %s", dirID) // Create nested directory subDirID, err := client.Mkdir(dirID, "Subdirectory") if err != nil { log.Fatalf("Failed to create subdirectory: %v", err) } log.Printf("Created subdirectory with ID: %s", subDirID) } ``` -------------------------------- ### Perform QR Code Login Source: https://context7.com/sheltonzhu/115driver/llms.txt Initiate a QR code login session, save the image, and poll for status updates to complete authentication. ```go package main import ( "log" "os" "time" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() // Start QR code session session, err := client.QRCodeStart() if err != nil { log.Fatalf("Failed to start QRCode session: %v", err) } // Get QR code image and save to file qrImage, err := session.QRCode() if err != nil { log.Fatalf("Failed to generate QRCode: %v", err) } os.WriteFile("qrcode.png", qrImage, 0644) log.Println("Scan qrcode.png with 115 app") // Poll for QR code status for { status, err := client.QRCodeStatus(session) if err != nil { log.Fatalf("Failed to check status: %v", err) } if status.IsWaiting() { log.Println("Waiting for scan...") } else if status.IsScanned() { log.Println("QR code scanned, waiting for confirmation...") } else if status.IsAllowed() { // Login with web app (or use QRCodeLoginWithApp for other apps) credential, err := client.QRCodeLogin(session) if err != nil { log.Fatalf("Login failed: %v", err) } log.Printf("Login successful! Cookie: %s", credential.Cookie()) break } else if status.IsExpired() { log.Fatal("QR code expired") } else if status.IsCanceled() { log.Fatal("Login canceled by user") } time.Sleep(2 * time.Second) } } ``` -------------------------------- ### Search Files Source: https://context7.com/sheltonzhu/115driver/llms.txt Queries files and directories using specific criteria such as file type, sorting order, and suffixes. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // Search with various options // Type values: 0=all, 1=folder, 2=document, 3=image, 4=video, 5=audio, 6=archive results, err := client.Search(&driver.SearchOption{ SearchValue: "report", Limit: 100, Offset: 0, Type: 2, // documents only Order: "user_ptime", // sort by time Asc: 0, // descending order Suffix: "pdf", // PDF files only }) if err != nil { log.Fatalf("Search failed: %v", err) } log.Printf("Found %d results", results.Count) for _, file := range results.Files { log.Printf("- %s (ID: %s, Size: %d, PickCode: %s)", file.Name, file.FileID, file.Size, file.PickCode) } } ``` -------------------------------- ### Build MCP Server Binary Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Builds the main MCP server binary for the 115driver package. Ensure you are in the correct directory before running. ```bash # Build the main MCP server binary go build -o mcp/115driver-mcp-server ./mcp/main.go ``` -------------------------------- ### Project Directory Structure Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Overview of the repository layout. ```text 115driver/ ├── pkg/ │ ├── driver/ # Core driver implementation │ │ ├── client.go # Client interface │ │ ├── login.go # Authentication │ │ ├── file.go # File operations │ │ ├── upload.go # Upload functionality │ │ ├── download.go # Download functionality │ │ ├── search.go # Search │ │ ├── share.go # Share files │ │ ├── offline.go # Offline download │ │ └── ... # Other modules │ └── crypto/ # Cryptography utilities └── mcp/ # MCP server implementation ``` -------------------------------- ### List Directory Files in Go Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Retrieves and prints a list of files from a specific directory ID. ```go package main import ( "github.com/SheltonZhu/115driver/pkg/driver" "log" ) func main() { client := driver.Default() // Create credentials and login cr, _ := driver.CredentialFromCookie("your_cookie") client = client.ImportCredential(cr) client.LoginCheck() // List files in root directory files, err := client.List("0") if err != nil { log.Fatalf("List failed: %v", err) } for _, file := range files { log.Printf("File: %s, Size: %d, Type: %s", file.Name, file.Size, file.Type) } } ``` -------------------------------- ### Run MCP Server Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md Run the MCP server executable with your 115 cookies. The server listens on stdin/stdout for MCP requests. ```bash ./mcp-server --cookie="UID=your_uid;CID=your_cid;SEID=your_seid" ``` -------------------------------- ### Authenticate with Cookies Source: https://context7.com/sheltonzhu/115driver/llms.txt Authenticate using UID, CID, SEID, and KID credentials parsed from a string or provided manually. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() // Method 1: Parse from cookie string cr := &driver.Credential{} err := cr.FromCookie("UID=123456;CID=abcdef;SEID=ghijkl;KID=mnopqr") if err != nil { log.Fatalf("Failed to parse cookie: %v", err) } // Method 2: Create credential manually cr = &driver.Credential{ UID: "123456", CID: "abcdef", SEID: "ghijkl", KID: "mnopqr", } // Import credentials and verify login client = client.ImportCredential(cr) if err := client.LoginCheck(); err != nil { log.Fatalf("Login failed: %v", err) } // Get user information userInfo, err := client.GetUser() if err != nil { log.Fatalf("Failed to get user info: %v", err) } log.Printf("Logged in as user ID: %d", userInfo.UserID) } ``` -------------------------------- ### Run All Tests Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Executes all tests within the project. This is a comprehensive check of the entire package. ```bash # Run all tests go test ./... ``` -------------------------------- ### Perform Rapid Upload in Go Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Uploads a file using its hash to the specified directory. Requires a valid cookie for authentication. ```go package main import ( "github.com/SheltonZhu/115driver/pkg/driver" "io" "log" "os" ) func main() { client := driver.Default() // Create credentials and login cr, _ := driver.CredentialFromCookie("your_cookie") client = client.ImportCredential(cr) client.LoginCheck() // Open the file file, err := os.Open("/path/to/local/file.zip") if err != nil { log.Fatalf("Failed to open file: %v", err) } defer file.Close() // Get file info fileInfo, err := file.Stat() if err != nil { log.Fatalf("Failed to get file info: %v", err) } // Rapid upload using file hash uploadID, err := client.RapidUploadOrByOSS( "0", // parent directory ID (0 for root) fileInfo.Name(), fileInfo.Size(), file, ) if err != nil { log.Fatalf("Rapid upload failed: %v", err) } log.Printf("Rapid upload started, init response: %+v", uploadID) } ``` -------------------------------- ### Add and Manage Offline Download Tasks Source: https://context7.com/sheltonzhu/115driver/llms.txt Add offline download tasks for HTTP, ED2K, and magnet links, list existing tasks, delete specific tasks, and clear completed tasks. Requires authentication. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // Add offline download tasks urls := []string{ "https://example.com/file.zip", "magnet:?xt=urn:btih:HASH...", "ed2k://|file|name|size|hash|/", } hashes, err := client.AddOfflineTaskURIs(urls, "0") // save to root directory if err != nil { log.Fatalf("Failed to add offline tasks: %v", err) } for i, hash := range hashes { log.Printf("Task %d added with hash: %s", i+1, hash) } // List offline tasks taskResp, err := client.ListOfflineTask(1) // page 1 if err != nil { log.Fatalf("Failed to list tasks: %v", err) } log.Printf("Total tasks: %d", taskResp.Total) for _, task := range taskResp.Tasks { log.Printf("Task: %s, Status: %s, Progress: %.2f%%", task.Name, task.GetStatus(), task.Percent*100) } // Delete specific tasks err = client.DeleteOfflineTasks(hashes, false) // false = keep downloaded files if err != nil { log.Fatalf("Failed to delete tasks: %v", err) } // Clear all completed tasks err = client.ClearOfflineTasks(0) // 0=completed, 1=all if err != nil { log.Fatalf("Failed to clear tasks: %v", err) } } ``` -------------------------------- ### Download File by Pick Code Source: https://context7.com/sheltonzhu/115driver/llms.txt Downloads a file using its pick code. Supports custom user agents and retrieves download information including URL and file size. Requires authentication. ```go package main import ( "io" "log" "os" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // Get download info using pick code pickCode := "abc123xyz" downloadInfo, err := client.Download(pickCode) if err != nil { log.Fatalf("Failed to get download info: %v", err) } log.Printf("Downloading: %s (%d bytes)", downloadInfo.FileName, downloadInfo.FileSize) log.Printf("Download URL: %s", downloadInfo.Url.Url) // Download with custom user agent downloadInfo, err = client.DownloadWithUA(pickCode, "Mozilla/5.0 Custom Agent") if err != nil { log.Fatalf("Download with UA failed: %v", err) } // Get file content reader, err := downloadInfo.Get() if err != nil { log.Fatalf("Failed to get file reader: %v", err) } // Save to local file outFile, _ := os.Create(downloadInfo.FileName) defer outFile.Close() written, _ := io.Copy(outFile, reader) log.Printf("Downloaded %d bytes to %s", written, downloadInfo.FileName) } ``` -------------------------------- ### Add Offline Download Task in Go Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Initiates an offline download task for a given URL to a target directory. ```go package main import ( "github.com/SheltonZhu/115driver/pkg/driver" "log" ) func main() { client := driver.Default() // Create credentials and login cr, _ := driver.CredentialFromCookie("your_cookie") client = client.ImportCredential(cr) client.LoginCheck() // Add offline download task url := "https://example.com/file.zip" taskIDs, err := client.AddOfflineTaskURIs([]string{url}, "0") // "0" for root directory if err != nil { log.Fatalf("Offline download failed: %v", err) } log.Printf("Offline download task created with hash: %s", taskIDs[0]) } ``` -------------------------------- ### File Operations (Rename, Move, Copy, Delete) Source: https://context7.com/sheltonzhu/115driver/llms.txt Performs standard file management tasks. Note that deleted files are moved to the recycle bin. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) fileID := "1234567890" targetDirID := "9876543210" // Rename a file or directory err := client.Rename(fileID, "new-filename.txt") if err != nil { log.Fatalf("Rename failed: %v", err) } log.Println("File renamed successfully") // Move files to another directory err = client.Move(targetDirID, "file1", "file2", "file3") if err != nil { log.Fatalf("Move failed: %v", err) } log.Println("Files moved successfully") // Copy files to another directory err = client.Copy(targetDirID, "file1", "file2") if err != nil { log.Fatalf("Copy failed: %v", err) } log.Println("Files copied successfully") // Delete files (moves to recycle bin) err = client.Delete("file1", "file2", "file3") if err != nil { log.Fatalf("Delete failed: %v", err) } log.Println("Files deleted successfully") } ``` -------------------------------- ### Manage Recycle Bin Items Source: https://context7.com/sheltonzhu/115driver/llms.txt List items in the recycle bin, restore specific items, or permanently delete them. Permanent deletion requires a password and is irreversible. Requires authentication. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // List items in recycle bin items, err := client.ListRecycleBin(0, 40) // offset=0, limit=40 if err != nil { log.Fatalf("Failed to list recycle bin: %v", err) } for _, item := range items { log.Printf("Deleted: %s (ID: %s, Size: %d, Parent: %s)", item.FileName, item.FileId, item.FileSize, item.ParentName) } // Restore items from recycle bin if len(items) > 0 { err = client.RevertRecycleBin(items[0].FileId) if err != nil { log.Fatalf("Failed to restore item: %v", err) } log.Printf("Restored: %s", items[0].FileName) } // Permanently delete items (requires password) // WARNING: This is irreversible! err = client.CleanRecycleBin("your_password", "item_id_1", "item_id_2") if err != nil { log.Fatalf("Failed to clean recycle bin: %v", err) } } ``` -------------------------------- ### Upload File with Rapid Upload Source: https://context7.com/sheltonzhu/115driver/llms.txt Uses SHA1 deduplication for efficient uploads with an automatic fallback to OSS for new files. ```go package main import ( "log" "os" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // Open local file file, err := os.Open("/path/to/upload/document.pdf") if err != nil { log.Fatalf("Failed to open file: %v", err) } defer file.Close() fileInfo, _ := file.Stat() // Upload using rapid upload with OSS fallback // "0" is root directory, can be replaced with target directory ID err = client.RapidUploadOrByOSS( "0", // parent directory ID fileInfo.Name(), // file name fileInfo.Size(), // file size file, // file reader ) if err != nil { log.Fatalf("Upload failed: %v", err) } log.Printf("Successfully uploaded: %s", fileInfo.Name()) } ``` -------------------------------- ### Run Tests with Verbose Output Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Executes tests with verbose output, showing the status of each test. Useful for debugging test failures. ```bash # Run tests with verbose output go test -v ./pkg/driver/ ``` -------------------------------- ### Search Files in Go Source: https://github.com/sheltonzhu/115driver/blob/main/README.md Searches for files using a keyword and a limit on the number of results. ```go package main import ( "github.com/SheltonZhu/115driver/pkg/driver" "log" ) func main() { client := driver.Default() // Create credentials and login cr, _ := driver.CredentialFromCookie("your_cookie") client = client.ImportCredential(cr) client.LoginCheck() // Search for files keyword := "document" results, err := client.Search(&driver.SearchOption{ SearchValue: keyword, Limit: 100, }) if err != nil { log.Fatalf("Search failed: %v", err) } log.Printf("Found %d results", results.Count) for _, result := range results.Files { log.Printf("File: %s, Size: %d", result.Name, result.Size) } } ``` -------------------------------- ### Upload Large File with Multipart Source: https://context7.com/sheltonzhu/115driver/llms.txt Handles large file uploads using multipart strategy with support for custom timeouts and token refresh intervals. ```go package main import ( "log" "os" "time" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) // Open large file file, err := os.Open("/path/to/large-video.mp4") if err != nil { log.Fatalf("Failed to open file: %v", err) } defer file.Close() fileInfo, _ := file.Stat() // Upload with multipart and custom options err = client.RapidUploadOrByMultipart( "0", // parent directory ID fileInfo.Name(), // file name fileInfo.Size(), // file size file, // file handle (must be *os.File) driver.UploadMultipartWithTimeout(48 * time.Hour), driver.UploadMultipartWithTokenRefreshTime(50 * time.Minute), ) if err != nil { log.Fatalf("Multipart upload failed: %v", err) } log.Printf("Successfully uploaded large file: %s", fileInfo.Name()) } ``` -------------------------------- ### Run Specific Test Function Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Runs a single, specific test function within a package. Use this to quickly verify a particular test case. ```bash # Run a specific test go test -v ./pkg/driver/ -run TestFunctionName ``` -------------------------------- ### Download Shared File Source: https://context7.com/sheltonzhu/115driver/llms.txt Downloads a file from a shared link using share code, receive code, and file ID. Retrieves file details like name, size, and download URL. Requires authentication. ```go package main import ( "log" "github.com/SheltonZhu/115driver/pkg/driver" ) func main() { client := driver.Default() cr := &driver.Credential{UID: "xxx", CID: "xxx", SEID: "xxx", KID: "xxx"} client.ImportCredential(cr) shareCode := "sw12abc" receiveCode := "1234" fileID := "9876543210" // Get shared file download info sharedInfo, err := client.DownloadByShareCode(shareCode, receiveCode, fileID) if err != nil { log.Fatalf("Failed to get shared download info: %v", err) } log.Printf("Shared file: %s", sharedInfo.FileName) log.Printf("File size: %d bytes", sharedInfo.FileSize) log.Printf("Download URL: %s", sharedInfo.URL.URL) } ``` -------------------------------- ### Run Tests for Specific Package Source: https://github.com/sheltonzhu/115driver/blob/main/CLAUDE.md Runs tests only for the specified package, useful for targeted testing during development. ```bash # Run tests for specific package go test ./pkg/driver/ ``` -------------------------------- ### Recycle Bin Tools API Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md API endpoints for managing the recycle bin. ```APIDOC ## POST /tools/call (listRecycleBin) ### Description Lists items in the recycle bin. ### Method POST ### Endpoint /tools/call ### Parameters #### Request Body - **name** (string) - Required - The name of the tool to call, which is "listRecycleBin". - **arguments** (object) - Required - The arguments for the tool. - **offset** (string) - Optional - Offset for pagination, default is 0. - **limit** (string) - Optional - Number of items to return, default is 40. ### Request Example ```json { "jsonrpc": "2.0", "id": "8", "method": "tools/call", "params": { "name": "listRecycleBin", "arguments": { "limit": "20" } } } ``` ### Response #### Success Response (200) (No specific success response fields are detailed in the provided text, typically returns a list of items in the recycle bin.) ``` ```APIDOC ## POST /tools/call (revertRecycleBin) ### Description Reverts items from the recycle bin. ### Method POST ### Endpoint /tools/call ### Parameters #### Request Body - **name** (string) - Required - The name of the tool to call, which is "revertRecycleBin". - **arguments** (object) - Required - The arguments for the tool. - **item_ids** (array of strings) - Required - IDs of items to revert. ### Request Example ```json { "jsonrpc": "2.0", "id": "9", "method": "tools/call", "params": { "name": "revertRecycleBin", "arguments": { "item_ids": ["item1", "item2"] } } } ``` ### Response #### Success Response (200) (No specific success response fields are detailed in the provided text, typically returns an empty object or success status.) ``` ```APIDOC ## POST /tools/call (cleanRecycleBin) ### Description Cleans items from the recycle bin. ### Method POST ### Endpoint /tools/call ### Parameters #### Request Body - **name** (string) - Required - The name of the tool to call, which is "cleanRecycleBin". - **arguments** (object) - Required - The arguments for the tool. - **password** (string) - Required - Password for cleaning recycle bin. - **item_ids** (array of strings) - Optional - IDs of items to clean. If not provided, all items might be cleaned depending on the server implementation. ### Request Example ```json { "jsonrpc": "2.0", "id": "10", "method": "tools/call", "params": { "name": "cleanRecycleBin", "arguments": { "password": "your_password", "item_ids": ["item3", "item4"] } } } ``` ### Response #### Success Response (200) (No specific success response fields are detailed in the provided text, typically returns an empty object or success status.) ``` -------------------------------- ### Directory Tools API Source: https://github.com/sheltonzhu/115driver/blob/main/mcp/mcp_example.md API endpoints for managing directories. ```APIDOC ## POST /tools/call (listDirectory) ### Description Lists files and directories in a specific directory. ### Method POST ### Endpoint /tools/call ### Parameters #### Request Body - **name** (string) - Required - The name of the tool to call, which is "listDirectory". - **arguments** (object) - Required - The arguments for the tool. - **dir_id** (string) - Optional - Directory ID to list, default is root directory (0). - **offset** (int64) - Optional - Offset for pagination, default is 0. - **limit** (int64) - Optional - Number of items to return, default is all items. ### Request Example ```json { "jsonrpc": "2.0", "id": "1", "method": "tools/call", "params": { "name": "listDirectory", "arguments": { "dir_id": "0" } } } ``` ### Response #### Success Response (200) - **content** (array of objects) - Contains the list of files and directories. - **type** (string) - Type of the item (e.g., "text"). - **text** (string) - JSON string representing the file/directory details. - **Id** (string) - Unique identifier of the item. - **Name** (string) - Name of the item. - **Size** (int64) - Size of the item in bytes. - **Type** (int) - Type of the item (1 for directory, 0 for file). - **CreateTime** (int64) - Timestamp of creation. #### Response Example ```json { "jsonrpc": "2.0", "id": "1", "result": { "content": [ { "type": "text", "text": "[{\"Id\":\"12345\",\"Name\":\"Documents\",\"Size\":0,\"Type\":1,\"CreateTime\":1234567890},{\"Id\":\"67890\",\"Name\":\"image.jpg\",\"Size\":1024,\"Type\":0,\"CreateTime\":1234567891}]" } ] } } ``` ``` ```APIDOC ## POST /tools/call (mkdir) ### Description Creates a new directory. ### Method POST ### Endpoint /tools/call ### Parameters #### Request Body - **name** (string) - Required - The name of the tool to call, which is "mkdir". - **arguments** (object) - Required - The arguments for the tool. - **parent_id** (string) - Required - Parent directory ID. - **name** (string) - Required - Name of the new directory. ### Request Example ```json { "jsonrpc": "2.0", "id": "2", "method": "tools/call", "params": { "name": "mkdir", "arguments": { "parent_id": "12345", "name": "New Folder" } } } ``` ### Response #### Success Response (200) (No specific success response fields are detailed in the provided text, typically returns an empty object or success status.) ```