多🌹444收拾收拾计算机视觉手机手机手机手机4大尺寸惆怅长岑长
??????????????????????????С??????????????P??????????????????????????????????????????????????????^??????????
????j??????????
? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!database/migrations/2025_09_08_072943_create_ai_music_pro_table.php 0000644 00000001734 15266620537 0020500 0 ustar 00 id();
$table->unsignedBigInteger('user_id')->index();
$table->string('file_path')->nullable();
$table->string('workbook_title');
$table->text('ai_music_prompt');
$table->integer('duration')->nullable();
$table->string('music_style')->nullable();
$table->timestamps();
// foreign key to users table
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('ai_music_pro');
}
};
database/migrations/2025_09_08_072943_add_music_slug_to_free_items.php 0000644 00000001253 15266620537 0021217 0 ustar 00 free_open_ai_items;
if (is_array($freeOpenAiItems) && ! in_array($slug, $freeOpenAiItems)) {
$freeOpenAiItems[] = $slug;
$settings->free_open_ai_items = $freeOpenAiItems;
$settings->save();
Setting::forgetCache();
}
}
/**
* Reverse the migrations.
*/
public function down(): void {}
};
extension.json 0000644 00000000205 15266620537 0007464 0 ustar 00 {
"name": "AiMusicPro",
"type": "extension",
"version": "1.1.0",
"description": "AiMusicPro extension for magicai"
}
System/AiMusicProServiceProvider.php 0000644 00000007410 15266620537 0013626 0 ustar 00
*
* @note When you create a new service provider, make sure to add it to the "MarketplaceServiceProvider". Otherwise, your Laravel application won’t recognize this provider, and the related functions won’t work properly.
* @note If you want to perform a specific action when an extension is uninstalled, you can use the UninstallExtensionServiceProviderInterface. By implementing this interface, you can define custom operations that will be triggered during the uninstallation of the extension.
* @note The registerKey() method is used to provide a unique identifier for the extension, which is essential for the healthy check and other functionalities.
*/
class AiMusicProServiceProvider extends ServiceProvider implements ExtensionRegisterKeyProviderInterface, UninstallExtensionServiceProviderInterface
{
public function register(): void
{
$this->registerConfig();
}
public function boot(Kernel $kernel): void
{
$this->registerTranslations()
->registerViews()
->registerRoutes()
->registerMigrations()
->publishAssets()
->registerComponents();
}
public function registerComponents(): static
{
// $this->loadViewComponentsAs('ai-music-pro', []);
return $this;
}
public function publishAssets(): static
{
$this->publishes([
// __DIR__ . '/../resources/assets/js' => public_path('vendor/ai-music-pro/js'),
// __DIR__ . '/../resources/assets/images' => public_path('vendor/ai-music-pro/images'),
], 'extension');
return $this;
}
public function registerConfig(): static
{
$this->mergeConfigFrom(__DIR__ . '/../config/aimusicpro.php', 'ai-music-pro');
return $this;
}
protected function registerTranslations(): static
{
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'ai-music-pro');
return $this;
}
public function registerViews(): static
{
$this->loadViewsFrom([__DIR__ . '/../resources/views'], 'ai-music-pro');
return $this;
}
public function registerMigrations(): static
{
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
return $this;
}
private function registerRoutes(): static
{
$this->router()
->group([
'middleware' => ['web', 'auth'],
'prefix' => 'dashboard/user/ai-music-pro/',
'as' => 'dashboard.user.ai-music-pro.',
'controller' => AiMusicProController::class,
], function (Router $router) {
$router->get('/', 'index')->name('index')->middleware(CheckTemplateTypeAndPlan::class);
$router->post('/generate', 'generate')->name('generate');
$router->get('/delete/{id}', 'delete')->name('delete');
});
return $this;
}
private function router(): Router|Route
{
return $this->app['router'];
}
public static function uninstall(): void
{
// TODO: Implement uninstall() method.
}
public function registerKey(): string
{
return 'ai-music-pro';
}
}
System/Models/AiMusicPro.php 0000644 00000000646 15266620537 0012021 0 ustar 00 id())->orderBy('id', 'desc')->paginate(10);
return view('ai-music-pro::index', compact('music'));
}
public function generate(Request $request): JsonResponse
{
$request->validate([
'workbook_title' => 'required|string|max:190',
'ai_music_prompt' => 'required|string|max:2000',
'duration' => 'nullable|integer|min:10|max:300',
'music_style' => 'nullable|string|max:190',
]);
$isDemo = Helper::appIsDemo();
// --- DEMO MODE CHECK (BEFORE GENERATION) ---
if ($isDemo) {
$duration = (int) $request->get('duration', 30); // Assume 30 seconds if not specified
$chkLmt = Helper::checkDemoSecondDailyLimit($duration);
if ($chkLmt->getStatusCode() === 429) {
return response()->json(['message' => $chkLmt->getData()->message, 'type' => 'error']);
}
}
$driver = Entity::driver(EntityEnum::ELEVENLABS_AI_MUSIC)->inputMinute(1)->calculateCredit();
try {
$driver->redirectIfNoCreditBalance();
} catch (Exception $e) {
return response()->json(['message' => $e->getMessage(), 'type' => 'error']);
}
$param = [
'prompt' => $request->get('ai_music_prompt', ''),
'model_id' => 'music_v1',
];
if ($request->filled('duration')) {
$param['music_length_ms'] = $request->get('duration') * 1000;
}
if ($request->filled('music_style')) {
$param['prompt'] .= ', in the style of ' . $request->get('music_style');
}
$elevenlabsService = new PackageElevenlabsService(ApiHelper::setElevenlabsKey());
$response = $elevenlabsService->AiMusicModel()->submit($param);
$fileUrl = $response->getData(true)['file_url'] ?? null;
if (empty($fileUrl)) {
return response()->json(['message' => __('Failed to generate music. Please try again.'), 'type' => 'error']);
}
$uploadsPath = public_path('uploads/' . $fileUrl);
if ($request->filled('duration')) {
$voiceLengthMinutes = $request->get('duration') / 60;
} else {
$voiceLengthMinutes = measureVoiceLength($uploadsPath);
}
$driver->inputMinute($voiceLengthMinutes)->calculateCredit()->decreaseCredit();
$this->storeMusicRecord(
$fileUrl,
$param,
$request->get('workbook_title', 'Song Title'),
$voiceLengthMinutes
);
// --- DEMO MODE: RECORD USED TIME (AFTER GENERATION) ---
if ($isDemo) {
$clientIp = Helper::getRequestIp();
$cacheKey = "demo_ai_usage_seconds_{$clientIp}";
$usedSeconds = Cache::get($cacheKey, 0);
$newTotal = $usedSeconds + ($voiceLengthMinutes * 60); // Convert minutes to seconds
Cache::put($cacheKey, $newTotal, now()->endOfDay());
}
$music = AiMusicPro::where('user_id', auth()->id())->orderBy('id', 'desc')->paginate(10);
$html2 = view('ai-music-pro::components.generator_sidebar_table', compact('music'))->render();
return response()->json([
'status' => 'success',
'message' => __('Music generated successfully!'),
'html2' => $html2,
]);
}
private function storeMusicRecord($fileUrl, $param, $title, $voiceLengthMinutes): void
{
$voiceLengthSeconds = null;
if ($voiceLengthMinutes !== null) {
$voiceLengthSeconds = $voiceLengthMinutes / 60;
} elseif (! empty($param['music_length_ms'])) {
$voiceLengthSeconds = $param['music_length_ms'] / 1000;
}
$data = [
'user_id' => auth()->id(),
'file_path' => $fileUrl ?? null,
'workbook_title' => $title,
'ai_music_prompt' => $param['prompt'] ?? null,
'duration' => $voiceLengthSeconds,
'music_style' => $param['music_style'] ?? null,
];
AiMusicPro::create($data);
}
public function delete($id): RedirectResponse
{
$music = AiMusicPro::where('user_id', auth()->id())->where('id', $id)->firstOrFail();
try {
if (file_exists(public_path('uploads/' . $music->file_path))) {
@unlink(public_path('uploads/' . $music->file_path));
}
$music->delete();
return redirect()->back()->with(['message' => __('Music deleted successfully!'), 'type' => 'success']);
} catch (Exception $e) {
return redirect()->back()->with(['message' => __('Failed to delete music. Please try again.'), 'type' => 'error']);
}
}
}
System/Http/Requests/.gitkeep 0000644 00000000016 15266620537 0012224 0 ustar 00 *
!.gitignore
System/Http/Resources/.gitkeep 0000644 00000000016 15266620537 0012363 0 ustar 00 *
!.gitignore
resources/views/index.blade.php 0000644 00000017360 15266620537 0012624 0 ustar 00 @php
$ai_music_options = [
'duration' => [
'' => __('None'),
'30' => '30 ' . __('seconds'),
'60' => '1 ' . __('minute'),
'120' => '2 ' . __('minutes'),
'180' => '3 ' . __('minutes'),
],
'music_style' => [
'' => __('None'),
'techno' => 'Techno',
'lofi' => 'Lo-Fi',
'pop' => 'Pop',
'jazz' => 'Jazz',
'rock' => 'Rock',
'classical' => 'Classical',
'hiphop' => 'Hip-Hop/Trap',
'edm' => 'EDM/House',
'reggae' => 'Reggae',
'ambient' => 'Ambient',
'cozy' => 'Cozy',
'relaxed' => 'Relaxed',
]
];
@endphp
@extends('panel.layout.app', ['disable_tblr' => true])
@section('title', __('AI Music Pro'))
@section('titlebar_subtitle', __('Create music tracks with AI'))
@section('content')