wow_api

repository·master·Indexed 43 days ago

https://github.com/illidan33/wow_api

A dual-purpose platform for World of Warcraft players to discover, create, and share in-game macros, and for addon developers to reference internal game APIs, events, and valid macro commands.

Tokens
1.9K
Snippets
7
Records
11
Agent score
55%

What's inside wow_api

  1. Overview of wow_api

    master

    The wow_api project serves two primary user groups: World of Warcraft players and WoW addon developers.

    For players, it acts as a macro tool platform where they can discover, create, and share in-game macro commands.

    For addon developers, it serves as a reference platform for querying World of Warcraft's internal APIs, events, and valid macro commands.

  2. Query World of Warcraft API and Events

    master

    Addon developers can use the wow_api platform to look up technical documentation required for plugin development, specifically:

    • Internal API Query (游戏内部api查询): Search for World of Warcraft's internal programming interfaces.
    • Event Query (游戏内部事件event查询): Look up game events that can be hooked by addons.
    • Macro Command Query (游戏内部合法宏命令查询): Verify valid macro commands available within the game.
  3. Use the macro tool for World of Warcraft

    master

    The macro tool provides three main ways to manage in-game commands:

    1. Fast Create (快速创建): Combines search and auto-generation. It returns a list of commands for players who want specific macros but do not know the exact syntax.
    2. Create by Hand (手动组合): Allows experienced players to manually combine specific commands using the tool's interface to build custom macros.
    3. Share and Search (分享及搜索): A community feature where players can upload their own collected macro commands and search for macros shared by other players.
  4. Access the home and chart pages

    master

    The index package provides handlers for rendering the main web interface:

    • Index: Renders index.html and initializes a login log via modules.CreateLoginLog. It sets the apiPage template variable to "home".
    • ChartIndex: Renders chart.html and sets the apiPage template variable to "chart".
  5. Use AuthMiddleware for route protection

    master

    The AuthMiddleware function is a Gin middleware used to protect routes. It checks for the presence of a token cookie. If the cookie is missing or empty, it aborts the request and renders the unauth.html template with a 401 Unauthorized status. If the token is present, it calls c.Next() to allow the request to proceed to the intended handler.

    // Example of applying the middleware in a Gin router
    router.GET("/protected", AuthMiddleware, ProtectedHandler)
  6. View macro pages with ViewIndex

    master

    The ViewIndex function serves as a router handler for rendering macro-related HTML pages. It supports dynamic page names via the name URL parameter.

    Behavior:

    • If no name parameter is provided, it defaults to home.
    • If the name parameter is set to verify, the handler performs a security check by comparing the token cookie against global.Config.VerifyCode. If they do not match, it returns a 404.html with a 401 Unauthorized status.
    • For all successful requests, it logs the access using modules.CreateLoginLog and renders an HTML template named macro_<name>.html.
    • The rendered template receives a context map containing apiPage, which is the string value of the requested name.
    // Example of how this handler might be registered in a Gin router
    router.GET("/macro/:name", macro.ViewIndex)
  7. Use ViewIndex to serve macro viewing pages

    master

    The ViewIndex function is a Gin handler used to serve specific macro viewing pages. It resolves the page name from the URL parameter name. If no name is provided, it defaults to home.

    If the requested page name is verify, the handler performs a security check by comparing the token cookie against the global.Config.VerifyCode. If the token is missing or incorrect, it returns a 404.html with a 401 Unauthorized status.

    Upon successful resolution, it logs the access via modules.CreateLoginLog and renders an HTML template named macro60_{name}.html, passing the apiPage string as data in the Gin context.

    // Example of how this handler is intended to be used within a Gin router
    router.GET("/macro60/:name", macro60.ViewIndex)
  8. Redirect to foreign API details with ForeignDetailIndex

    master

    The ForeignDetailIndex handler is used to redirect users to external or foreign API documentation. It retrieves an API object by its id path parameter and then uses modules.GetApiDetailUrlByID to construct a destination URL based on the type query parameter and the API's name.

    • Path Parameter: id (used to fetch the API via modules.GetApiByID)
    • Query Parameter: type (used to determine the destination URL logic)

    If the API ID is not found, it returns a 404.html page. On success, it performs an http.StatusFound (302) redirect.

    // Example usage pattern:
    // GET /api/foreign/123?type=external
    // Redirects to the URL generated by modules.GetApiDetailUrlByID
  9. Access the API Index page

    master

    The ApiIndex handler serves the main API landing page. It uses a URL parameter name to determine which specific API sub-page to render. If no name is provided in the path, it defaults to rendering the home page. It also triggers a login log entry via modules.CreateLoginLog for the requested page.

    // Example of how the handler is structured for Gin
    // Expected URL pattern: /api/:name
    func ApiIndex(c *gin.Context) {
        // ... logic to render api_{name}.html
    }
  10. Retrieve chart data via GetChartData

    master

    The GetChartData function provides time-series data for charts, specifically tracking IP counts, HTML page views, and API usage. It queries the api_login_log table.

    Query Parameters:

    • sd: Start date in YYYY-MM-DD format. If omitted, it defaults to global.Config.ChartDay days ago.
    • ed: End date in YYYY-MM-DD format. If omitted, it defaults to the current date.

    Response Format: Returns a JSON object with:

    • code: 0 for success, 500 for database errors.
    • title: An array of date strings (YYYY-MM-DD) sorted chronologically.
    • data: An array of objects containing:
      • Name: The metric name ("IP", "Page/10", or "Api/10").
      • Data: An array of integers corresponding to the values for each date in title.
    // Example GET request
    // GET /get-chart-data?sd=2023-01-01&ed=2023-01-31
    
    // Example JSON Response
    {
      "code": 0,
      "title": ["2023-01-01", "2023-01-02"],
      "data": [
        { "Name": "IP", "Data": [10, 12] },
        { "Name": "Page/10", "Data": [5, 6] },
        { "Name": "Api/10", "Data": [8, 9] }
      ]
    }
  11. View API details with DetailIndex

    master

    The DetailIndex handler retrieves and displays detailed information for a specific API entity. It requires an id path parameter and accepts an optional type query parameter.

    • Path Parameter: id (used to fetch the API via modules.GetApiByID)
    • Query Parameter: type (passed to the template)

    If the API ID is not found, it returns a 404.html page.

    // Example usage pattern:
    // GET /api/detail/123?type=some_type
    // Returns api_detail.html with 'api' and 'type' data