-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
8644527
commit b9d490e
Showing
2 changed files
with
88 additions
and
92 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 |
---|---|---|
@@ -1,89 +1,89 @@ | ||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
import App from '../../Models/App' | ||
import { string } from '@ioc:Adonis/Core/Helpers' | ||
|
||
// DEPRECATED - Use StoreController instead | ||
|
||
export default class AppsController { | ||
public async index({ view, params, request }: HttpContextContract) { | ||
const query = request.qs()["query"] | ||
const cat: number = params['category'] | ||
let apps: App[] | ||
|
||
if (query) { | ||
apps = await App.query() | ||
.orderBy("downloads", "desc") | ||
.orWhereLike("name", `%${query}%`) | ||
.orWhereLike("desc", `%${query}%`) | ||
.limit(15) | ||
} else { | ||
const q = App.query() | ||
.orderBy("downloads", "desc") | ||
.limit(15) | ||
|
||
if (cat) { | ||
q.where('category', cat) | ||
} | ||
|
||
apps = await q | ||
} | ||
|
||
return view.share({ | ||
category: cat, | ||
apps, | ||
query | ||
}).render('apps/index') | ||
} | ||
|
||
public async show({ view, params }: HttpContextContract) { | ||
const app = await App.query() | ||
.where('id', params.id) | ||
//.preload('author') | ||
.firstOrFail() | ||
|
||
return view.share({ app }).render('apps/product') | ||
} | ||
|
||
public async create({ view }: HttpContextContract) { | ||
return view.render('apps/create') | ||
} | ||
|
||
public async createProcess({ auth, request, response }: HttpContextContract) { | ||
const data = request.body() | ||
const img = request.file('img') | ||
|
||
if (!auth.user) return response.status(403) | ||
|
||
if (img) { | ||
const filename = img.fileName + string.generateRandom(8) + (img.extname ? "." + img.extname : "") | ||
await img.moveToDisk('/appicons', { | ||
name: filename | ||
}) | ||
//imgUrl = process.env.ACCESS_ADDRESS + "/uploads/appicons/" + filename | ||
} | ||
|
||
await App.create({ | ||
userId: auth.user.id, | ||
name: data.name, | ||
desc: data.desc, | ||
//image: imgUrl, | ||
source_url: data.source_url, | ||
//releases: data.releases, | ||
category: data.categories | ||
}) | ||
} | ||
|
||
public async getAppJson({ params, response }: HttpContextContract) { | ||
const app = await App.findOrFail(params["id"]) | ||
return response.send(app.toJSON()) | ||
} | ||
|
||
public async appinstalldemo({ view }: HttpContextContract) { | ||
return view.render('apps/appinstalldemo'); | ||
} | ||
|
||
public async product({ view }: HttpContextContract) { | ||
return view.render('apps/product'); | ||
} | ||
} | ||
// import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
// import App from '../../Models/App' | ||
// import { string } from '@ioc:Adonis/Core/Helpers' | ||
|
||
// // DEPRECATED - Use StoreController instead | ||
|
||
// export default class AppsController { | ||
// public async index({ view, params, request }: HttpContextContract) { | ||
// const query = request.qs()["query"] | ||
// const cat: number = params['category'] | ||
// let apps: App[] | ||
|
||
// if (query) { | ||
// apps = await App.query() | ||
// .orderBy("downloads", "desc") | ||
// .orWhereLike("name", `%${query}%`) | ||
// .orWhereLike("desc", `%${query}%`) | ||
// .limit(15) | ||
// } else { | ||
// const q = App.query() | ||
// .orderBy("downloads", "desc") | ||
// .limit(15) | ||
|
||
// if (cat) { | ||
// q.where('category', cat) | ||
// } | ||
|
||
// apps = await q | ||
// } | ||
|
||
// return view.share({ | ||
// category: cat, | ||
// apps, | ||
// query | ||
// }).render('apps/index') | ||
// } | ||
|
||
// public async show({ view, params }: HttpContextContract) { | ||
// const app = await App.query() | ||
// .where('id', params.id) | ||
// //.preload('author') | ||
// .firstOrFail() | ||
|
||
// return view.share({ app }).render('apps/product') | ||
// } | ||
|
||
// public async create({ view }: HttpContextContract) { | ||
// return view.render('apps/create') | ||
// } | ||
|
||
// public async createProcess({ auth, request, response }: HttpContextContract) { | ||
// const data = request.body() | ||
// const img = request.file('img') | ||
|
||
// if (!auth.user) return response.status(403) | ||
|
||
// if (img) { | ||
// const filename = img.fileName + string.generateRandom(8) + (img.extname ? "." + img.extname : "") | ||
// await img.moveToDisk('/appicons', { | ||
// name: filename | ||
// }) | ||
// //imgUrl = process.env.ACCESS_ADDRESS + "/uploads/appicons/" + filename | ||
// } | ||
|
||
// await App.create({ | ||
// userId: auth.user.id, | ||
// name: data.name, | ||
// desc: data.desc, | ||
// //image: imgUrl, | ||
// source_url: data.source_url, | ||
// //releases: data.releases, | ||
// category: data.categories | ||
// }) | ||
// } | ||
|
||
// public async getAppJson({ params, response }: HttpContextContract) { | ||
// const app = await App.findOrFail(params["id"]) | ||
// return response.send(app.toJSON()) | ||
// } | ||
|
||
// public async appinstalldemo({ view }: HttpContextContract) { | ||
// return view.render('apps/appinstalldemo'); | ||
// } | ||
|
||
// public async product({ view }: HttpContextContract) { | ||
// return view.render('apps/product'); | ||
// } | ||
// } | ||
|
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