Skip to content

Commit

Permalink
init seatable api
Browse files Browse the repository at this point in the history
  • Loading branch information
shuntian committed Oct 15, 2021
0 parents commit 5c45906
Show file tree
Hide file tree
Showing 8 changed files with 2,018 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": [ "@babel/preset-env" ],
"plugins": [ "@babel/plugin-transform-modules-commonjs" ]
}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# dependencies
/node_modules

# misc
.DS_Store

# log
*.log

# dist
/dist

# lib
/lib
1,848 changes: 1,848 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "seatable-api",
"version": "1.0.0",
"description": "A tool library for accessing seatable base, providing interface services for third-party developers",
"files": [
"dist",
"package.json",
"package-lock.json"
],
"main": "./lib/index.js",
"scripts": {
"clean": "rm -rf dist && mkdir dist",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/babel src --out-dir lib",
"prepublishOnly": "npm run clean && npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/seatable/seatable-api.git"
},
"author": "seafile",
"license": "ISC",
"bugs": {
"url": "https://github.com/seatable/seatable-api/issues"
},
"homepage": "https://github.com/seatable/seatable-api#readme",
"dependencies": {
"axios": "0.23.0"
},
"devDependencies": {
"@babel/cli": "7.15.7",
"@babel/core": "7.15.8",
"@babel/preset-env": "7.15.8"
}
}
28 changes: 28 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/bash

echo "====================="
echo "auto git"
echo "======= 🤪 ========="
echo ""
echo "git add ."

git add .
git status

echo ""
echo "git commit -m 'update version'"
echo ""

git commit -m 'update version'

current_banch=$(git symbolic-ref --short -q HEAD)

echo ""
echo "git push origin $current_banch"
echo ""

git push origin $current_banch

echo "npm publish"
echo ""
npm publish
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SeatableAPI

## Introduce

A tool library for accessing seatable base, providing interface services for third-party developers

##
70 changes: 70 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import axios from "axios";
import { getAccessToken } from './utils';

class SeatableAPI {

constructor() {
this.appName = '';
this.accessToken = '';
this.dtableServer = '';
this.dtableSocket = '';
this.lang = 'en';
this.req = null;
}

async buildConnectionWithBase(config) {
const response = await getAccessToken(config);
const { app_name, access_token, dtable_uuid, dtable_server, dtable_socket } = response.data;
this.appName = app_name;
this.accessToken = access_token;
this.dtableServer = dtable_server;
this.dtableSocket = dtable_socket;
this.dtableUuid = dtable_uuid;
this.req = axios.create({
baseURL: this.dtableServer,
headers: {Authorization: 'Token ' + this.accessToken}
});
}

getDTable() {
const url = `dtables/${this.dtableUuid}/?lang=${this.lang}`;
return this.req.get(url);
}

getRelatedUsers() {
const url = `api/v1/dtables/${this.dtableUuid}/related-users/`;
return this.req.get(url);
}

listViews(tableName) {
const url = `api/v1/dtables/${this.dtableUuid}/views/`;
const params = {
table_name: encodeURIComponent(tableName),
}
return this.req.get(url, params);
}

listColumns(tableName, viewName) {
const url = `api/v1/dtables/${this.dtableUuid}/columns/`;
const params = {
table_name: tableName,
view_name: viewName
}
return this.req.get(url, {params});
}

listRows(tableName, viewName) {
const url = `api/v1/dtables/${this.dtableUuid}/rows/`;
const params = {
table_name: tableName,
view_name: viewName,
convert_link_id: true,
}
return this.req.get(url, {params});
}

}

const seatableAPI = new SeatableAPI();

export default seatableAPI;
12 changes: 12 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from "axios";

const getAccessToken = () => {
const { server, APIToken } = config;
const url = server + '/api/v2.1/dtable/app-access-token/';
const headers = { 'Authorization': 'Token ' + APIToken };
return axios.get(url, { headers: headers });
};

export {
getAccessToken
}

0 comments on commit 5c45906

Please sign in to comment.