-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gaojie
committed
Sep 23, 2022
0 parents
commit ffc8316
Showing
22 changed files
with
493 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
write: true, | ||
prefix: '^', | ||
plugin: 'autod-egg', | ||
test: [ | ||
'test', | ||
'benchmark', | ||
], | ||
dep: [ | ||
'egg', | ||
'egg-scripts', | ||
], | ||
devdep: [ | ||
'egg-ci', | ||
'egg-bin', | ||
'egg-mock', | ||
'autod', | ||
'autod-egg', | ||
'eslint', | ||
'eslint-config-egg', | ||
], | ||
exclude: [ | ||
'./test/fixtures', | ||
'./dist', | ||
], | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "eslint-config-egg", | ||
"root": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
pull_request: | ||
branches: | ||
- main | ||
- master | ||
schedule: | ||
- cron: '0 2 * * *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [16] | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
steps: | ||
- name: Checkout Git Source | ||
uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install Dependencies | ||
run: npm i | ||
|
||
- name: Continuous Integration | ||
run: npm run ci | ||
|
||
- name: Code Coverage | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
logs/ | ||
npm-debug.log | ||
yarn-error.log | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
coverage/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
*.sw* | ||
*.un~ | ||
typings/ | ||
.nyc_output/ | ||
database/config.json | ||
config/config.local.js | ||
config/config.prod.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
|
||
module.exports = { | ||
config: path.join(__dirname, "database/config.json"), | ||
"migrations-path": path.join(__dirname, "database/migrations"), | ||
"seeders-path": path.join(__dirname, "database/seeders"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# 用于小程序后端的简单应用(eggjs开发) | ||
|
||
|
||
|
||
## 数据库连接 | ||
|
||
/config/config.local.js | ||
```js | ||
"use strict"; | ||
|
||
exports.sequelize = { | ||
dialect: "mysql", | ||
host: "0.0.0.0", | ||
port: 3306, | ||
database: "name", | ||
username: "user", | ||
password: "password", | ||
}; | ||
``` | ||
|
||
/config/config.prod.js | ||
```js | ||
"use strict"; | ||
|
||
exports.sequelize = { | ||
dialect: "mysql", | ||
host: "0.0.0.0", | ||
port: 3306, | ||
database: "name", | ||
username: "user", | ||
password: "password", | ||
}; | ||
``` | ||
|
||
/database/cofig.json | ||
|
||
`用于migration连接数据库` | ||
```json | ||
{ | ||
"development": { | ||
"dialect": "mysql", | ||
"host": "0.0.0.0", | ||
"port": 3306, | ||
"database": "name", | ||
"username": "user", | ||
"password": "password" | ||
} | ||
} | ||
``` | ||
|
||
|
||
### Development | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
### Deploy | ||
|
||
```bash | ||
$ npm start | ||
$ npm stop | ||
``` | ||
|
||
|
||
[egg]: https://eggjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
|
||
const Controller = require("egg").Controller; | ||
|
||
function toInt(str) { | ||
if (typeof str === "number") return str; | ||
if (!str) return str; | ||
return parseInt(str, 10) || 0; | ||
} | ||
|
||
class EpController extends Controller { | ||
async index() { | ||
const ctx = this.ctx; | ||
const query = { | ||
limit: toInt(ctx.query.limit), | ||
offset: toInt(ctx.query.offset), | ||
}; | ||
ctx.body = await ctx.model.Ep.findAll(query); | ||
} | ||
|
||
async newEps() { | ||
const ctx = this.ctx; | ||
|
||
ctx.body = await ctx.model.NewEp.findAll({ limit: 1 }); | ||
} | ||
} | ||
|
||
module.exports = EpController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
|
||
const Controller = require("egg").Controller; | ||
|
||
class HomeController extends Controller { | ||
async index() { | ||
const { ctx } = this; | ||
ctx.body = "hi there"; | ||
} | ||
} | ||
|
||
module.exports = HomeController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use strict"; | ||
|
||
const Controller = require("egg").Controller; | ||
|
||
function toInt(str) { | ||
if (typeof str === "number") return str; | ||
if (!str) return str; | ||
return parseInt(str, 10) || 0; | ||
} | ||
|
||
class TrackController extends Controller { | ||
async show() { | ||
const ctx = this.ctx; | ||
const { id } = this.ctx.params; | ||
const { limit = 20, current = 1 } = this.ctx.query; | ||
const _limit = toInt(limit); | ||
|
||
// 页数从1开始 | ||
const _current = toInt(current); | ||
const offset = (_current - 1) * _limit; | ||
|
||
ctx.body = await ctx.model.Track.findAndCountAll({ | ||
where: { ep_Id: id }, | ||
limit: _limit, | ||
offset, | ||
}); | ||
} | ||
} | ||
|
||
module.exports = TrackController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use strict"; | ||
|
||
module.exports = (app) => { | ||
const { STRING, INTEGER, DATE } = app.Sequelize; | ||
|
||
const Ep = app.model.define("ep", { | ||
id: { | ||
type: INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
_id: { type: STRING, field: "_id" }, | ||
name: STRING(250), | ||
img: STRING(250), | ||
sort: INTEGER, | ||
created_at: DATE, | ||
updated_at: DATE, | ||
}); | ||
|
||
return Ep; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use strict"; | ||
|
||
module.exports = (app) => { | ||
const { STRING, DATE, INTEGER, BOOLEAN } = app.Sequelize; | ||
|
||
const NewEp = app.model.define("newEp", { | ||
id: { | ||
type: INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
hideAudio: BOOLEAN, | ||
newEpIds: STRING(300), | ||
createdAt: DATE, | ||
updatedAt: DATE, | ||
}); | ||
|
||
return NewEp; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use strict"; | ||
|
||
module.exports = (app) => { | ||
const { STRING, INTEGER, DATE } = app.Sequelize; | ||
|
||
const Track = app.model.define("track", { | ||
id: { | ||
type: INTEGER, | ||
primaryKey: true, | ||
autoIncrement: true, | ||
}, | ||
_id: { type: STRING, field: "_id" }, | ||
title: STRING(250), | ||
epId: STRING(250), | ||
length: STRING(250), | ||
src: STRING(250), | ||
sort: INTEGER, | ||
created_at: DATE, | ||
updated_at: DATE, | ||
}); | ||
|
||
return Track; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict"; | ||
|
||
/** | ||
* @param {Egg.Application} app - egg application | ||
*/ | ||
module.exports = (app) => { | ||
const { router, controller } = app; | ||
router.get("/", controller.home.index); | ||
|
||
router.get("/eps", controller.eps.index); | ||
router.get("/newEps", controller.eps.newEps); | ||
|
||
router.get("/tracks/:id", controller.tracks.show); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint valid-jsdoc: "off" */ | ||
|
||
"use strict"; | ||
|
||
/** | ||
* @param {Egg.EggAppInfo} appInfo app info | ||
*/ | ||
module.exports = (appInfo) => { | ||
/** | ||
* built-in config | ||
* @type {Egg.EggAppConfig} | ||
**/ | ||
const config = {}; | ||
|
||
// use for cookie sign key, should change to your own and keep security | ||
config.keys = appInfo.name + "_1663737137179_1189"; | ||
|
||
// add your middleware config here | ||
config.middleware = []; | ||
|
||
// add your user config here | ||
const userConfig = { | ||
// myAppName: 'egg', | ||
}; | ||
|
||
return { | ||
...config, | ||
...userConfig, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
|
||
/** @type Egg.EggPlugin */ | ||
exports.sequelize = { | ||
enable: true, | ||
package: "egg-sequelize", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
|
||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
const { INTEGER, DATE, STRING } = Sequelize; | ||
await queryInterface.createTable("eps", { | ||
id: { type: INTEGER, primaryKey: true, autoIncrement: true }, | ||
_id: STRING(250), | ||
name: STRING(250), | ||
img: STRING(250), | ||
sort: INTEGER, | ||
created_at: DATE, | ||
updated_at: DATE, | ||
}); | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
await queryInterface.dropTable("eps"); | ||
}, | ||
}; |
Oops, something went wrong.