Skip to content

SheltonZhu/115driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

134 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

115driver

A comprehensive Go library for interacting with 115 cloud storage. This package provides a full-featured driver for 115.com's API, supporting login, file operations, upload/download, and more.

Go Report Card Release Go Reference License

Installation

go get github.com/SheltonZhu/115driver

Features

Authentication

  • Import credentials from cookies
  • QR code login
  • Get signed-in user information

File Operations

  • List files and directories
  • Rename files and directories
  • Move files and directories
  • Copy files and directories
  • Delete files and directories
  • Create directories
  • Download files
  • Upload files
  • Rapid upload (similar to Google Drive's rapid upload)
  • Search files
  • Get file information by ID
  • Get file statistics
  • Download files via share code
  • Offline download

Recycle Bin

  • List deleted items
  • Restore deleted items
  • Clean recycle bin

Additional Features

  • Share files via share code
  • File tagging
  • Batch operations

Quick Start

Basic Usage

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!")
}

Download a File

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!")
}

Upload a File

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)
}

Rapid Upload

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)
}

List Files in a Directory

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)
    }
}

Search Files

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)
    }
}

Offline Download

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])
}

API Reference

For detailed API documentation, visit pkg.go.dev.

Troubleshooting

Login Issues

If you encounter login issues:

  1. Make sure your cookie is valid and not expired
  2. Check that all required fields (UID, CID, SEID, KID) are present
  3. Try logging in through the web interface first to obtain a fresh cookie

Upload/Download Issues

If upload or download fails:

  1. Verify file paths are correct
  2. Check your internet connection
  3. Ensure you have sufficient storage space
  4. Check the returned error message for specific details

Rate Limiting

The 115 API may have rate limits. If you encounter rate limiting errors:

  1. Add delays between operations
  2. Implement retry logic with exponential backoff
  3. Consider using a proxy if needed

Project Structure

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

Star History

Star History Chart

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Contributors

SheltonZhu
SheltonZhu
xhofe
xhofe
Ovear
Ovear
power721
power721

License

MIT

About

This is a 115 cloud driver package.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages