npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-zhousan

v1.0.0

Published

[![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependency Status][david-image]][david-url] [![License][license-image]][license-url] [![Downloads][downloads-image]

Downloads

4

Readme

koa-static

NPM version Build status Test coverage Dependency Status License Downloads

Koa static file serving middleware, wrapper for koa-send.

Installation

$ npm install koa-static

API

const Koa = require('koa');
const app = new Koa();
app.use(require('koa-static')(root, opts));
  • root root directory string. nothing above this root directory can be served
  • opts options object.

Options



router.post('/user/logon',indexController.Logon)
router.post('/user/sendcode',indexController.SendCode)
router.post('/user/login',indexController.Login)

router.post('/car/add',indexController.AddCar)
router.post('/car/delete',indexController.DeleteCar)
router.get('/car/show',indexController.CarShow)
router.put('/car/update',indexController.UpdateCar)

  • maxage Browser cache max-age in milliseconds. defaults to 0
  • hidden Allow transfer of hidden files. defaults to false
  • index Default file name, defaults to 'index.html'
  • defer If true, serves after return next(), allowing any downstream middleware to respond first.
  • gzip Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.
  • br Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.
  • setHeaders Function to set custom headers on response.
  • extensions Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to false)

Example

const query = require('../db/query');
const md5 = require('md5')


const CheckAccount = async(params)=>{
    var sql = ` select * from userinfo where account='${params.account}' or phone='${params.phone}' `
    return await query(sql)
}

const AddUser = async(params)=>{
    var newpassword=md5(params.password)
    var sql =` insert into userinfo (account,password,phone) 
    value('${params.account}','${newpassword}','${params.phone}') `
    return await query(sql)
}


const AddCar = async(params)=>{
    var sql = ` select * from car where shopid='${params.shopid}' and userid='${params.userid}' `
    var cardata = await query(sql)
    if(cardata.length>0){
        var sql2 = ` update car set count=count+${params.count} where shopid='${params.shopid}' and userid='${params.userid}' `
        return await query(sql2)
    }
    var sql3 = ` insert into car (shopid,count,userid) 
    values('${params.shopid}','${params.count}','${params.userid}') `
    return await query(sql3)
}

const DeleteCar = async (params) => {
    var sql = ` delete from car where id in(${params.ids}) `
    return await query(sql)
}

const CarShow = async(params)=>{
    var page = params.page;
    var size = params.size;
    var sql = ` select b.shopname,b.price,a.count,a.count*b.price zpric,a.id from car a
    join shop b on a.shopid=b.id where a.userid='${params.userid}' `
    if(params.shopname){
        sql+=` and b.shopname like '%${params.shopname}%' `
    }
    var zcount = (await query(sql)).length
    sql+=` limit ${(page-1)*size},${size} `
    var cardata = await query(sql)
    return { cardata,zcount }
}

const UpdateCar = async(params)=>{
    console.log(params);
    var sql2 = ` select * from car where id='${params.id}' `
    var cardata = await query(sql2)
    var sql = ` update car set count= `
    if(params.data==true){
        if(cardata[0].count==1){
            return {affectedRows:0}
        }
        sql+=` count-1 `
    }else{
        sql+=` count+1 `
    }
    sql+=` where id=${params.id} `
    return await query(sql)
}





See also

Options

  • maxage Browser cache max-age in milliseconds. defaults to 0
  • hidden Allow transfer of hidden files. defaults to false
  • index Default file name, defaults to 'index.html'
  • defer If true, serves after return next(), allowing any downstream middleware to respond first.
  • gzip Try to serve the gzipped version of a file automatically when gzip is supported by a client and if the requested file with .gz extension exists. defaults to true.
  • br Try to serve the brotli version of a file automatically when brotli is supported by a client and if the requested file with .br extension exists (note, that brotli is only accepted over https). defaults to true.
  • setHeaders Function to set custom headers on response.
  • extensions Try to match extensions from passed array to search for file when no extension is sufficed in URL. First found is served. (defaults to false)

Example

const indexService = require('../service/index');
const redis = require('../extend/redis')
const jwt=require('../extend/help')
const xlsx = require('node-xlsx')

const Logon = async(ctx)=>{
    var res1 = await indexService.CheckAccount(ctx.request.body)
    if(res1.length>0){
        return ctx.body={
            code:403,
            message:''
        }
    }
    var res2 = await indexService.AddUser(ctx.request.body)
    if(res2.affectedRows>0){
        return ctx.body={
            code:200,
            message:''
        }
    }else{
        return ctx.body={
            code:403,
            message:''
        }
    }
}


const SendCode = async(ctx)=>{
    var phone=ctx.request.body.phone;
    if(!phone){
        return ctx.body={
            code:403,
            message:''
        }
    }
    var checkphone=/^1[3-9]\d{9}$/
    if(!checkphone.test(phone)){
        return ctx.body={
            code:403,
            message:''
        }
    }
    var res1 = await indexService.CheckAccount(ctx.request.body)
    if(res1.length==0){
        return ctx.body={
            code:403,
            message:''
        }
    }
    var rediscode = await redis.get(phone)
    if(rediscode == null){
        var code = Math.random().toFixed(6).slice(-6)
        await redis.setex(phone,60,code);
        return ctx.body={
            code:200,
            message:'',
            data:code
        }
    }else{
        return ctx.body={
            code:403,
            message:''
        }
    }
}

const Login = async (ctx) => {
    var res1 = await indexService.CheckAccount(ctx.request.body)
    if (res1.length == 0) {
        return ctx.body = {
            code: 403,
            message: ""
        }
    }
    var rediscode = await redis.get(ctx.request.body.phone)
    if (rediscode == ctx.request.body.code) {
        var token = await jwt.signtoken(res1[0])
        return ctx.body = {
            code: 200,
            message: "",
            data: 'Bearer ' + token
        }
    } else {
        return ctx.body = {
            code: 403,
            message: ""
        }
    }
}


const AddCar=async(ctx)=>{
    ctx.request.body.userid=ctx.state.user.data.id
    var res = await indexService.AddCar(ctx.request.body)
    if(res.affectedRows>0){
        return ctx.body={
            code:200,
            message:''
        }
    }else{
        return ctx.body={
            code:403,
            message:''
        }
    }
}

const DeleteCar = async (ctx) => {
    var res = await indexService.DeleteCar(ctx.request.query)
    if (res.affectedRows > 0) {
        return ctx.body = {
            code: 200,
            message: ""
        }
    } else {
        return ctx.body = {
            code: 403,
            message: ""
        }
    }
}

const CarShow=async(ctx)=>{
    ctx.request.query.userid = ctx.state.user.data.id
    var res = await indexService.CarShow(ctx.request.query)
    if(res.cardata.length>0){
        return ctx.body={
            code:200,
            message:'',
            data:res
        }
    }else{
        return ctx.body={
            code:403,
            menubar:''
        }
    }
}

const UpdateCar = async(ctx)=>{
    var res = await indexService.UpdateCar(ctx.request.body)
    if(res.affectedRows>0){
        return ctx.body={
            code:200,
            message:''
        }
    }else{
        return ctx.body={
            code:403,
            message:''
        }
    }
}



See also

CCCCCCAAAAARRRR

<body>
    <div>
        <span>    </span><input type="text" id="shopname">
        <input type="button" value="   " onclick="Query()">
    </div>
    <table>
        <thead>
            <tr>
                <td>     </td>
                <td>     </td>
                <td>     </td>
                <td>     </td>
                <td>     </td>
            </tr>
        </thead>
        <tbody id="data"></tbody>
    </table>
    <div>
        <input type="button" value="  " onclick="Page(true)">
        <input type="button" value="  " onclick="Page(false)">
    </div>
</body>


<script>
    var page = 1;
    var size = 3;
    var zcount = 0
    const CarShow = async () => {
        var data = {
            page,
            size,
            shopname: document.getElementById('shopname').value
        }
        var res = await request.get('/car/show', {
            params: data
        })
        if (res.data.code == 200) {
            document.getElementById('data').innerHTML = res.data.data.cardata.map((i) => {
                return ` 
            <tr>
                <td>${i.shopname}</td>
                <td>${i.price}</td>
                <td>
                    <input type="button" value="-" onclick="Count(${i.id},true)">
                    ${i.count}
                    <input type="button" value="+" onclick="Count(${i.id},false)">
                    </td>
                <td>${i.zprce}</td>
                <td>   </td>
            </tr>
                `
            }).join('')
            zcount = res.data.data.zcount
        } else {
            document.getElementById('data').innerHTML = ''
        }
    }
    CarShow()
    const Page = (data) => {
        if (data) {
            if (page == 1) {
                return alert('')
            } else {
                page = page - 1
            }
        } else {
            if (page == Math.ceil(zcount / size)) {
                return alert('')
            } else {
                page = page + 1
            }
        }
        CarShow()
    }
    const Query = () => {
        page = 1
        CarShow()
    }
    const Count = async (id, data) => {
        var datas = {
            id,
            data
        }
        var res = await request.put('/car/update', datas)
        if (res.data.code == 200) {
            CarShow()
        } else {
            return alert('')
        }
    }
</script>

See also

LOGIN

<body>
    <div>
        <span> </span><input type="text" id="phone">
        <br>
        <span>  </span><input type="text" id="code">
        <br>
        <input type="button" value="  " onclick="SendCode()">
        <input type="button" value="   " onclick="Login()">
    </div>
</body>

<script>
    const SendCode=async()=>{
        var res = await request.post('/user/sendcode',{phone:document.getElementById('phone').value})
        if(res.data.code==200){
            return alert(res.data.data)
        }else{
            return alert(res.data.message)
        }
   }

   const Login=async()=>{
    var data={
        phone:document.getElementById('phone').value,
        code:document.getElementById('code').value,
    }
    var res = await request.post('/user/login',data);
    if(res.data.code==200){
        localStorage.setItem('token', res.data.data)
        alert('   ')
    }
   }
</script>

See also

License

MIT