| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- import APIRepository from '../classes/APIRepository'
- import { appApi } from 'src/boot/axios'
- import { Content } from 'src/models/Content'
- import { ProductList } from 'src/models/Product'
- import { Comment } from 'src/models/Comment'
- import { APIGateway } from 'src/api/APIGateway'
- const APIAdresses = {
- base: '/c',
- search: '/search',
- admin: '/admin/contents',
- timestampSet: '/timepoint',
- show: (id) => '/c/' + id,
- delete: '/admin/contents/destroy',
- bulkUpdate: '/admin/contents/bulk-update',
- presigned: '/admin/upload/presigned-request',
- bulkEditText: '/admin/contents/bulk-edit-text',
- bulkEditTags: '/admin/contents/bulk-edit-tags',
- favored: (id) => '/c/' + id + '/favored',
- update: (id) => `/admin/contents/${id}/`,
- getTimestamp: (id) => `/timepoint/${id}`,
- showAdmin: (id) => '/admin/contents/' + id,
- deleteTimestamp: (id) => `/timepoint/${id}`,
- updateTimestamp: (id) => `/timepoint/${id}`,
- unfavored: (id) => '/c/' + id + '/unfavored',
- relatedProducts: (id) => '/c/' + id + '/products',
- timestampBookmarkStatus: (id, status) => '/c/timepoint/' + id + '/' + status,
- saveComment: '/comment',
- updateComment: (id) => '/comment/' + id,
- watchedVideo: '/watched',
- unWatchedVideo: '/unwatched',
- adminContent: {
- create: {
- base: '/admin/user'
- },
- edit: {
- base: '/admin/user/'
- },
- index: {
- base: '/admin/user'
- },
- show: {
- base: '/admin/user/'
- }
- },
- scheduleManagement: {
- create: {
- base: '/admin/user'
- },
- edit: {
- base: '/admin/user/'
- },
- index: {
- base: '/admin/user'
- },
- show: {
- base: '/admin/user/'
- }
- }
- }
- export default class ContentAPI extends APIRepository {
- constructor() {
- super('content', appApi, '/c/', new Content(), APIAdresses)
- this.CacheList = {
- admin: this.name + this.APIAdresses.admin,
- show: id => this.name + this.APIAdresses.show(id),
- favored: id => this.name + this.APIAdresses.favored(id),
- unfavored: id => this.name + this.APIAdresses.unfavored(id),
- showAdmin: id => this.name + this.APIAdresses.showAdmin(id),
- update: id => this.name + this.APIAdresses.update(id),
- relatedProducts: id => this.name + this.APIAdresses.relatedProducts(id),
- search: this.name + this.APIAdresses.search,
- delete: this.name + this.APIAdresses.delete,
- timestampSet: this.name + this.APIAdresses.timestampSet,
- bulkEditText: this.name + this.APIAdresses.bulkEditText,
- bulkUpdate: this.name + this.APIAdresses.bulkUpdate,
- bulkEditTags: this.name + this.APIAdresses.bulkEditTags,
- getTimestamp: id => this.name + this.APIAdresses.getTimestamp(id),
- updateTimestamp: id => this.name + this.APIAdresses.updateTimestamp(id),
- deleteTimestamp: id => this.name + this.APIAdresses.deleteTimestamp(id),
- presigned: this.name + this.APIAdresses.presigned
- }
- }
- show(data, cache = { TTL: 1000 }) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.show(data),
- cacheKey: this.CacheList.show(data),
- ...(cache && { cache }),
- resolveCallback: (response) => {
- return new Content(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- favored(data = {}, cache = { TTL: 1000 }) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.favored(data),
- cacheKey: this.CacheList.favored(data),
- ...(cache !== undefined && { cache }),
- resolveCallback: (response) => {
- return response.data
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- unfavored(data = {}, cache = { TTL: 1000 }) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.unfavored(data),
- cacheKey: this.CacheList.unfavored(data),
- ...(cache !== undefined && { cache }),
- resolveCallback: (response) => {
- return response.data
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- showAdmin(contentId, cache) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.showAdmin(contentId),
- cacheKey: this.CacheList.showAdmin(contentId),
- ...(cache && { cache }),
- resolveCallback: (response) => {
- const content = new Content(response.data.data)
- // fillFakeData(content)
- return content
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- update(data = {}) {
- return this.sendRequest({
- apiMethod: 'put',
- api: this.api,
- request: this.APIAdresses.update(data.id),
- cacheKey: this.CacheList.update(data.id),
- resolveCallback: (response) => {
- return new Content(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- },
- data: {
- display: 1,
- ...data
- }
- // data: this.getNormalizedSendData({
- // contentset_id: null, // contentSet Id
- // isFree: null, // contentSet Id
- // name: null, // Title for content,
- // description: null, // Description for content
- // thumbnail: null, // thumbnail for contentfd
- // validSinceDate: null, // time for publish content
- // forrest_tree: null, // tree for content
- // order: null, // order of content
- // enable: null, // content status
- // display: 1 // content display status
- // }, data)
- })
- }
- relatedProducts(contentId, cache) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.relatedProducts(contentId),
- cacheKey: this.CacheList.relatedProducts(contentId),
- ...(cache && { cache }),
- resolveCallback: (response) => {
- return new ProductList(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- bulkEditText(data) {
- return this.sendRequest({
- apiMethod: 'put',
- api: this.api,
- request: this.APIAdresses.bulkEditText,
- cacheKey: this.CacheList.bulkEditText,
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return response.data
- },
- rejectCallback: (error) => {
- return error
- },
- data
- })
- }
- bulkUpdate(data) {
- return this.sendRequest({
- apiMethod: 'put',
- api: this.api,
- request: this.APIAdresses.bulkUpdate,
- cacheKey: this.CacheList.bulkUpdate,
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return response.data
- },
- rejectCallback: (error) => {
- return error
- },
- data
- })
- }
- bulkEditTags(data) {
- return this.sendRequest({
- apiMethod: 'put',
- api: this.api,
- request: this.APIAdresses.bulkEditTags,
- cacheKey: this.CacheList.bulkEditTags,
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return response.data
- },
- rejectCallback: (error) => {
- return error
- },
- data
- })
- }
- deleteContents(data) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.delete,
- cacheKey: this.CacheList.delete,
- ...(data?.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return response.data
- },
- rejectCallback: (error) => {
- return error
- },
- data
- })
- }
- search(data = {}) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.search,
- cacheKey: this.CacheList.search,
- ...(data.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return {
- sets: response.data.data.sets,
- products: response.data.data.products,
- videos: response.data.data.videos
- }
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- SetTimestamp(data = {}, cache) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.timestampSet,
- cacheKey: this.CacheList.timestampSet,
- ...(cache && { cache }),
- resolveCallback: (response) => {
- return {
- timestamp: response.data
- }
- },
- rejectCallback: (error) => {
- return error
- },
- data: this.getNormalizedSendData({
- content_id: null, // content Id
- title: null, // Title for Timestamp
- time: null // time of Video for timestamp in seconds
- }, data.data)
- })
- }
- UpdateTimestamp(data = {}, cache) {
- return this.sendRequest({
- apiMethod: 'put',
- api: this.api,
- request: this.APIAdresses.updateTimestamp(data.id),
- cacheKey: this.CacheList.updateTimestamp(data.id),
- ...(cache && { cache }),
- resolveCallback: (response) => {
- return {
- timestamp: response.data
- }
- },
- rejectCallback: (error) => {
- return error
- },
- data: this.getNormalizedSendData({
- content_id: null, // content Id
- title: null, // Title for Timestamp
- time: null // time of Video for timestamp in seconds
- }, data)
- })
- }
- GetTimestamp(data = {}, cache) {
- return this.sendRequest({
- apiMethod: 'get',
- api: this.api,
- request: this.APIAdresses.getTimestamp(data.id),
- cacheKey: this.CacheList.getTimestamp(data.id),
- ...(cache && { cache }),
- resolveCallback: (response) => {
- return {
- timestamp: response.data
- }
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- DeleteTimestamp(data = {}, cache) {
- return this.sendRequest({
- apiMethod: 'delete',
- api: this.api,
- request: this.APIAdresses.deleteTimestamp(data.id),
- cacheKey: this.CacheList.deleteTimestamp(data.id),
- ...(cache && { cache }),
- resolveCallback: (response) => {
- return {
- timestamp: response.data
- }
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- getPresigned(data = {}) {
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.presigned,
- cacheKey: this.CacheList.presigned,
- ...(data.cache && { cache: data.cache }),
- resolveCallback: (response) => {
- return response.data.data
- },
- rejectCallback: (error) => {
- return error
- },
- data: this.getNormalizedSendData({
- bucket: null, // file name(test)
- key: null // file with type(type.mp4)
- }, data.data)
- })
- }
- setBookmarkTimepointFavoredStatus(data = {}) {
- const mergedData = this.getNormalizedSendData({
- id: '',
- status: 'favored'
- }, data)
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.timestampBookmarkStatus(mergedData.id, mergedData.status),
- resolveCallback: (response) => {
- const defaultMessageObject = {
- message: '' // String
- }
- return this.getNormalizedSendData(defaultMessageObject, response.data).message
- },
- rejectCallback: (error) => {
- return error
- }
- })
- }
- getConsultingContentList(isPro) {
- const setId = isPro ? 1597 : 1213
- return APIGateway.set.getContents(setId)
- }
- saveComment(data = {}) {
- const mergedData = this.getNormalizedSendData({
- commentable_id: '',
- commentable_type: 'content',
- comment: ''
- }, data)
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.saveComment,
- resolveCallback: (response) => {
- return new Comment(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- },
- data: mergedData
- })
- }
- updateComment(data = {}) {
- const mergedData = this.getNormalizedSendData({
- id: '',
- data: {}
- }, data)
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.updateComment(mergedData.id),
- resolveCallback: (response) => {
- return new Comment(response.data.data)
- },
- rejectCallback: (error) => {
- return error
- },
- data: mergedData.data
- })
- }
- setVideoWatched(data = {}) {
- const mergedData = this.getNormalizedSendData({
- watchable_id: '',
- watchable_type: 'content'
- }, data)
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.watchedVideo,
- resolveCallback: (response) => {
- const defaultResponseObject = {
- id: '',
- watchable_id: '',
- watchable_type: 'content',
- watchable: new Content(),
- seconds_watched: null
- }
- return this.getNormalizedSendData(defaultResponseObject, response.data.data)
- },
- rejectCallback: (error) => {
- return error
- },
- data: mergedData
- })
- }
- setVideoUnWatched(data = {}) {
- const mergedData = this.getNormalizedSendData({
- watchable_id: '',
- watchable_type: 'content'
- }, data)
- return this.sendRequest({
- apiMethod: 'post',
- api: this.api,
- request: this.APIAdresses.unWatchedVideo,
- resolveCallback: (response) => {
- const defaultResponseObject = {
- message: '' // String
- }
- return this.getNormalizedSendData(defaultResponseObject, response.data.data)
- },
- rejectCallback: (error) => {
- return error
- },
- data: mergedData
- })
- }
- }
- // const fillFakeData = (content) => {
- // content.forrest_tree_tags = forrestTreeTags
- // content.hls = 'https://alaatv.com/hls/input.m3u8'
- // }
- // const forrestTreeTags = [
- // {
- // id: '63ff427566344faf860f0f9f',
- // title: 'دبیر 1',
- // parent: {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // },
- // ancestors: [
- // {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // }
- // ],
- // order: '0',
- // type: null,
- // number_of_children: 0,
- // updated_at: '2023-03-01 15:49:18',
- // created_at: '2023-03-01 15:47:57'
- // },
- // {
- // id: '63ff427c66344faf860f0fa0',
- // title: 'دبیر 2',
- // parent: {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // },
- // ancestors: [
- // {
- // id: '63f37272c590054efc012d12',
- // title: 'دبیر'
- // }
- // ],
- // order: '2',
- // type: null,
- // number_of_children: 1,
- // updated_at: '2023-03-01 15:49:18',
- // created_at: '2023-03-01 15:48:04'
- // }
- // ]
|