4 Commits

1224 changed files with 521 additions and 101879 deletions

5
.gitignore vendored
View File

@@ -129,8 +129,3 @@ lint/tmp/
app/release/
app/debug/
*.apk
# Dashboard local files
dashboard/node_modules/
dashboard/server.log
dashboard/config.json

3
.idea/.gitignore generated vendored
View File

@@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

1
.idea/.name generated
View File

@@ -1 +0,0 @@
StreamPlayer

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
</component>
</project>

6
.idea/compiler.xml generated
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="21" />
</component>
</project>

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetSelector">
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
</selectionStates>
</component>
</project>

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DeviceTable">
<option name="columnSorters">
<list>
<ColumnSorterState>
<option name="column" value="Name" />
<option name="order" value="ASCENDING" />
</ColumnSorterState>
</list>
</option>
</component>
</project>

18
.idea/gradle.xml generated
View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="CHOOSE_PER_TEST" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

10
.idea/migrations.xml generated
View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

7
.idea/misc.xml generated
View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
</set>
</option>
</component>
</project>

6
.idea/vcs.xml generated
View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,9 +0,0 @@
# StreamPlayer v10.0
## Cambios en esta versión
- **Actualización a versión 10.0**: Nueva versión mayor del StreamPlayer
- Versión estable con mejoras acumuladas de versiones anteriores
- Sistema de actualizaciones automáticas activado
Esta versión marca un hito importante en el desarrollo de StreamPlayer, consolidando todas las mejoras y características implementadas previamente.

View File

@@ -1,26 +0,0 @@
# StreamPlayer v10.1.3
## Cambios en esta versión
### Corrección de Carga de Eventos
- **Sistema de fallback con múltiples URLs**: Implementado sistema inteligente que intenta múltiples URLs de eventos cuando la principal no está disponible:
- `https://streamtpcloud.com/eventos.json` (URL original)
- `https://streamtp10.com/eventos.json` (URL actual)
- `https://streamtpmedia.com/eventos.json` (URL anterior)
- **Seguimiento automático de redirecciones HTTP**: El cliente ahora sigue automáticamente las redirecciones HTTP (códigos 301, 302, 303, 307, 308), lo que permite adaptarse a cambios de URL del servidor sin necesidad de actualizar la app.
- **Memoria de URL exitosa**: La app recuerda cuál fue la última URL que funcionó correctamente y la intenta primero en futuras peticiones, mejorando el rendimiento y la fiabilidad.
### Detalles Técnicos
- Modificado `EventRepository.java` para implementar:
- Lógica de reintento secuencial con múltiples URLs
- Seguimiento manual de redirecciones (hasta 5 consecutivas)
- Persistencia de la última URL exitosa en SharedPreferences
- Manejo mejorado de errores con mensajes descriptivos
### Problema Resuelto
Esta versión corrige el error: *"Unable to resolve host 'streamtpcloud.com': No address associated with hostname"* que ocurría cuando el servidor de eventos cambió su dominio. La app ahora se adapta automáticamente a estos cambios sin intervención del usuario.

View File

@@ -1,60 +0,0 @@
# StreamPlayer v10.1.4 - Mejoras de Interfaz
## Correcciones Implementadas
### 1. Botón de Actualización Más Visible
- **Archivo**: `app/src/main/res/drawable/btn_refresh_selector.xml` (nuevo)
- **Descripción**: El botón de actualizar eventos ahora cambia a un color ámbar brillante (#FFC107) con borde grueso cuando está enfocado, mejorando significativamente la visibilidad para control remoto.
### 2. Prevención de Navegación Entre Secciones
- **Archivo**: `app/src/main/java/com/streamplayer/MainActivity.java`
- **Descripción**: Al hacer scroll después del último evento, la aplicación se detiene en lugar de pasar a la sección de canales, mejorando la experiencia de usuario.
### 3. Barra de Indicador de Scroll
- **Archivos**: `app/src/main/res/layout/activity_main.xml`, `app/src/main/res/drawable/scrollbar_vertical.xml` (nuevo)
- **Descripción**: Agregada barra de scroll visual a la derecha de la lista de contenido como indicador de posición (no navegable).
## Cambios Técnicos
### Nuevo Archivo: btn_refresh_selector.xml
```xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#FFC107" />
<corners android:radius="8dp" />
<stroke android:width="4dp" android:color="#FFD54F" />
</shape>
</item>
<!-- ... otros estados ... -->
</selector>
```
### Modificación: MainActivity.java
- Agregado `RecyclerView.OnScrollListener` en `showEvents()` para prevenir scroll más allá del último evento
### Modificación: activity_main.xml
- Botón refresh usa `@drawable/btn_refresh_selector`
- RecyclerView ahora tiene `android:scrollbars="vertical"` y `scrollbarThumbVertical`
### Nuevos Colores: colors.xml
- `refresh_button_default`: #2A2A2A
- `refresh_button_focused`: #FFC107
- `refresh_button_focused_border`: #FFD54F
- `refresh_button_pressed`: #FF9800
## Compatibilidad
- Versión mínima de Android: API 21+
- Compilado con SDK 34
- Probado en Android TV con control remoto
## Instalación
1. Descargar `StreamPlayer-10.1.4-debug.apk`
2. Habilitar "Fuentes desconocidas" en configuraciones de seguridad
3. Instalar el APK
4. Disfrutar las mejoras de interfaz
## Notas de Desarrollo
- La barra de scroll es puramente visual (indicador)
- El foco del botón refresh ahora usa color ámbar de alto contraste
- El scroll se detiene correctamente al final de la lista de eventos

View File

@@ -1,48 +0,0 @@
# StreamPlayer v10.1.5 - Correcciones Críticas
## Correcciones Implementadas
### 1. Scroll Listener Corregido
- **Problema**: El último evento aparecía solo a la mitad y requería bajar/subir muchas veces para verlo completo
- **Solución**: Cambiado de `findFirstVisibleItemPosition()` a `findLastCompletelyVisibleItemPosition()`
- Ahora el scroll solo se detiene cuando el último elemento está COMPLETAMENTE visible
### 2. Barra de Scroll Más Visible
- **Problema**: La barra indicadora no era visible (30% de opacidad)
- **Solución**:
- Opacidad aumentada de #4DFFFFFF (30%) a #CCFFFFFF (80%)
- Ancho de la barra aumentado a 8dp
- Radio de esquinas aumentado a 4dp para mejor apariencia
- Estilo cambiado de `outsideOverlay` a `insideInset`
- Agregado `scrollbarFadeDuration="0"` para que nunca se desvanezca
### 3. URLs Actualizadas
- **Problema**: Ciertos ISP bloquean las URLs viejas
- **Solución**: Eliminado sistema de fallback múltiples URLs
- Ahora usa únicamente: `https://streamtp10.com/eventos.json`
- Código simplificado, más eficiente y sin bloqueos
## Archivos Modificados
### EventRepository.java
- Simplificado para usar solo streamtp10.com
- Eliminado código de fallback no necesario
- Eliminado KEY_WORKING_URL y lógica asociada
### MainActivity.java
- Scroll listener corregido para usar `findLastCompletelyVisibleItemPosition()`
### scrollbar_vertical.xml
- Color cambiado a #CCFFFFFF (80% opacidad)
- Ancho definido en 8dp
- Radio de esquinas a 4dp
### activity_main.xml
- `scrollbarStyle` cambiado a `insideInset`
- `scrollbarSize` definido en 8dp
- `scrollbarFadeDuration` en 0 (siempre visible)
## Compatibilidad
- Versión mínima de Android: API 21+
- Compilado con SDK 34
- Probado en Android TV con control remoto

View File

@@ -1,42 +0,0 @@
# StreamPlayer v10.1.6 - Corrección de Control Remoto y Scrollbar
## Correcciones Implementadas
### 1. Control Remoto - Prevención de Navegación
- **Problema**: Al presionar el botón abajo del control remoto en el último evento, se iba a la sección de canales
- **Solución**: Agregado `setOnKeyListener` para interceptar teclas de navegación
- Ahora intercepta `KEYCODE_DPAD_DOWN` cuando está en el último elemento
- Combina scroll listener táctil + manejo de teclas del control remoto
### 2. Barra de Scroll Más Visible
- **Problema**: La barra de seguimiento no era visible
- **Solución**:
- Color del thumb: Blanco sólido (#FFFFFFFF) - antes 80%
- Ancho aumentado a 12dp (antes 8dp)
- Radio de esquinas: 6dp (antes 4dp)
- Track oscuro agregado (#1A1A1A)
- `scrollbarAlwaysDrawVerticalTrack="true"` para siempre visible
## Archivos Modificados
### MainActivity.java
- Import agregado: `android.view.KeyEvent`
- `setOnKeyListener` agregado en `showEvents()` para interceptar DPAD_DOWN
- Combina con scroll listener existente para cobertura completa
### scrollbar_vertical.xml
- Color cambiado a blanco sólido (#FFFFFFFF)
- Ancho: 12dp
- Radio: 6dp
### activity_main.xml
- `scrollbarSize="12dp"` (antes 8dp)
- `scrollbarTrackVertical="@color/scrollbar_track"` agregado
- `scrollbarAlwaysDrawVerticalTrack="true"` agregado
### colors.xml
- Nuevo color: `scrollbar_track` (#1A1A1A)
## Compatibilidad
- Android TV con control remoto
- Versión mínima: API 21+

View File

@@ -1,22 +0,0 @@
# StreamPlayer v10.1.7 - Corrección de Navegación y Scrollbar Permanente
## Correcciones Implementadas
### 1. Barra de Desplazamiento Permanente
- **Feature**: Se agregó `android:fadeScrollbars="false"` al `RecyclerView` de eventos.
- **Beneficio**: La barra de desplazamiento ahora es visible permanentemente, permitiendo al usuario saber su posición (inicio, medio, final) en todo momento sin tener que interactuar primero.
### 2. Navegación al Final de la Lista (Bug Fix)
- **Problema**: Al presionar "abajo" en el último evento, el foco saltaba involuntariamente a la sección de canales.
- **Solución**: Se implementó un `LinearLayoutManager` personalizado que intercepta la búsqueda de foco (`onInterceptFocusSearch`).
- **Detalle**: Cuando se detecta `FOCUS_DOWN` en el último elemento de la lista, la acción se bloquea, manteniendo al usuario en la lista de eventos.
- **Limpieza**: Se eliminaron los `OnKeyListener` y `OnScrollListener` anteriores que eran menos efectivos.
## Archivos Modificados
### MainActivity.java
- Implementación de `LinearLayoutManager` anónimo con `onInterceptFocusSearch`.
- Eliminación de listeners redundantes.
### activity_main.xml
- `android:fadeScrollbars="false"` añadido a `content_list`.

View File

@@ -1,21 +0,0 @@
# StreamPlayer v10.1.8 - Actualización de DNS y Dominios
## Cambios Críticos
### 1. Actualización de Dominios
- Se ha migrado toda la infraestructura de canales y eventos al nuevo dominio: `streamtp10.com`.
- Actualización de URLs base para todos los canales en `ChannelRepository`.
- Actualización del endpoint de eventos a `https://streamtp10.com/eventos.json`.
- Corrección del Header `Referer` en las peticiones de resolución.
### 2. Configuración Robusta de DNS (Anti-Bloqueo)
- Implementación de un nuevo sistema centralizado de red (`NetworkUtils`).
- **DNS Primario**: Google DNS over HTTPS (`8.8.8.8`, `8.8.4.4`).
- **DNS Secundario**: AdGuard DNS over HTTPS (`94.140.14.14`, `94.140.15.15`) como respaldo automático si Google falla.
- **DNS Terciario**: DNS del sistema (ISP) como último recurso.
- Se ha eliminado el uso de `HttpURLConnection` en `EventRepository` en favor de `OkHttpClient` con la nueva configuración DNS, asegurando que la carga de la guía de eventos también evite bloqueos.
## Beneficios
- Mayor resistencia a bloqueos regionales e interferencias de ISP.
- Recuperación automática si el proveedor de DNS principal (Google) no es accesible.
- Corrección de problemas de carga de canales debido al cambio de dominio del proveedor.

View File

@@ -113,60 +113,12 @@ StreamPlayer ahora consulta automáticamente las releases públicas del reposito
Si por algún motivo olvidas subir el manifiesto, la app igualmente tomará el primer asset `.apk` de la release, pero no podrá forzar versiones mínimas.
### Dashboard de Dispositivos y Bloqueo Remoto
Para saber en qué equipo está instalada la app y bloquear el acceso cuando lo necesites, se incluye un dashboard liviano en `dashboard/`:
1. Instala dependencias y ejecuta el servidor:
```bash
cd dashboard
npm install
npm start # escucha en http://localhost:4000
```
2. Copia `dashboard/config.example.json` a `dashboard/config.json` y completa `telegramBotToken` + `telegramChatId` (o usa variables de entorno `TELEGRAM_BOT_TOKEN` / `TELEGRAM_CHAT_ID`).
3. Ajusta `DEVICE_REGISTRY_URL` en `app/build.gradle` para apuntar al dominio/puerto donde despliegues el servidor (ya configurado como `http://194.163.191.200:4000`).
4. Distribuye el APK; cada instalación reportará `ANDROID_ID`, modelo, IP pública y país.
5. Entra a `http://TU_HOST:4000/` para ver el listado, asignar alias, bloquear/desbloquear o validar tokens.
El servidor guarda los datos en `dashboard/data/devices.json`, por lo que puedes versionarlo o respaldarlo fácilmente. Cada registro almacena:
- `deviceId`: `Settings.Secure.ANDROID_ID` del equipo
- `deviceName`, `manufacturer`, `model`, `osVersion`
- `appVersionName`/`Code`
- `ip`, `country` detectados automáticamente
- `firstSeen`, `lastSeen`, `blocked`, `notes`, `verification.status`
Cuando presionas “Bloquear”, la app recibe la respuesta `{"blocked": true}` y muestra un diálogo irreversible hasta que lo habilites. Esto añade una capa adicional de control aparte del sistema de actualizaciones.
### Flujo dentro de la app y tokens divididos
### Flujo dentro de la app
- Cada vez que se abre `MainActivity` se consulta `https://gitea.cbcren.online/api/v1/repos/renato97/app/releases/latest`.
- Si `versionCode` del servidor es mayor al instalado se muestra un diálogo para actualizar; el usuario puede abrir la release o descargarla directamente.
- Si `minSupportedVersionCode` es mayor al instalado la app bloqueará el uso hasta actualizar, cumpliendo con el requerimiento de controlar instalaciones.
- La descarga se gestiona con `DownloadManager` y, una vez completada, se lanza el instalador usando FileProvider.
- Mientras el dashboard mantenga un dispositivo "Pendiente" o "Bloqueado", la app muestra un diálogo con el motivo y la mitad del token que debe compartir la persona.
Cada instalación genera un token interno dividido en dos:
1. **Parte cliente**: se muestra en el diálogo del dispositivo bloqueado para que el usuario pueda copiarla.
2. **Parte admin**: llega al bot de Telegram configurado junto con la IP, país y datos del dispositivo.
Para autorizar un dispositivo pendiente:
1. Obtén la parte cliente desde el usuario (visible en pantalla).
2. Copia la parte admin del mensaje de Telegram.
3. En el dashboard presiona “Verificar token” e introduce ambas mitades. Si coinciden, el estado pasa a "Verificado" y la app se desbloquea automáticamente.
4. A partir de allí puedes bloquear/desbloquear manualmente cuando quieras.
También puedes gestionar todo desde Telegram:
- `/allow <deviceId> <token_cliente>` autoriza el dispositivo (verifica el token y lo desbloquea).
- `/deny <deviceId> <token_cliente> [motivo]` lo bloquea con un motivo opcional.
- `/pending` lista los registros que aún esperan un token válido.
Cada nuevo registro dispara una notificación de Telegram con la parte admin del token y recordatorios de esos comandos.
## 📱 Estructura del Proyecto

Binary file not shown.

View File

@@ -1,639 +0,0 @@
# VLC Player Migration Plan for Android App
## Current State Analysis
- **Location**: `/home/ren/futbol/`
- **Current Player**: ExoPlayer/Media3 1.5.0
- **Main Files**:
- `app/src/main/java/com/streamplayer/PlayerActivity.java`
- `app/src/main/java/com/streamplayer/StreamUrlResolver.java`
- `app/src/main/res/layout/activity_player.xml`
- **Key Features**: HLS streams, custom headers, retry logic, loading indicators, error handling
## Target State
- **New Player**: libvlc for Android (VLC Android SDK)
- **DRM Support**: ClearKey DRM for protected streams
- **Preserve**: All existing functionality
---
## Phase 1: Build Configuration Changes
### File: `app/build.gradle`
**Remove Media3 dependencies:**
```gradle
// REMOVE these lines (52-57):
implementation 'androidx.media3:media3-exoplayer:1.5.0'
implementation 'androidx.media3:media3-exoplayer-hls:1.5.0'
implementation 'androidx.media3:media3-datasource-okhttp:1.5.0'
implementation 'androidx.media3:media3-ui:1.5.0'
implementation 'androidx.media3:media3-ui-leanback:1.5.0'
implementation 'androidx.media3:media3-session:1.5.0'
```
**Add VLC Android SDK dependency:**
```gradle
// ADD after line 57:
// VLC Android SDK
implementation 'org.videolan.android:libvlc-all:3.5.4'
// Alternative: Use specific modules for smaller APK
// implementation 'org.videolan.android:libvlc:3.5.4'
```
---
## Phase 2: Layout Changes
### File: `app/src/main/res/layout/activity_player.xml`
**Current (lines 10-15):**
```xml
<androidx.media3.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="fill"
app:use_controller="true" />
```
**Replace with VLC SurfaceView:**
```xml
<org.videolan.libvlc.util.VLCVideoLayout
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- OR use SurfaceView directly for more control -->
<SurfaceView
android:id="@+id/player_surface"
android:layout_width="match_parent"
android:layout_height="match_parent" />
```
**Note**: Keep all other UI elements unchanged (toolbar, loading indicator, error message).
---
## Phase 3: PlayerActivity Rewrite
### File: `app/src/main/java/com/streamplayer/PlayerActivity.java`
**Import Changes:**
```java
// REMOVE these imports (14-28):
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.common.MediaItem;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.exoplayer.DefaultRenderersFactory;
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector;
import androidx.media3.datasource.okhttp.OkHttpDataSource;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.hls.HlsMediaSource;
import androidx.media3.exoplayer.drm.DrmSessionManager;
import androidx.media3.ui.PlayerView;
import androidx.media3.common.util.Util;
import androidx.annotation.OptIn;
import androidx.media3.common.util.UnstableApi;
// ADD VLC imports:
import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;
import org.videolan.libvlc.interfaces.IVLCVout;
import org.videolan.libvlc.util.VLCVideoLayout;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
```
**Class Member Variables (lines 51-66):**
```java
// REPLACE:
private PlayerView playerView;
private ExoPlayer player;
private DefaultTrackSelector trackSelector;
// WITH:
private VLCVideoLayout playerView; // OR SurfaceView playerSurface
private LibVLC libVlc;
private MediaPlayer mediaPlayer;
private SurfaceView surfaceView;
```
**onCreate Method (lines 68-98):**
```java
// MODIFY initViews() call:
private void initViews() {
playerView = findViewById(R.id.player_view); // VLCVideoLayout
// OR if using SurfaceView:
surfaceView = findViewById(R.id.player_surface);
loadingIndicator = findViewById(R.id.loading_indicator);
errorMessage = findViewById(R.id.error_message);
channelLabel = findViewById(R.id.player_channel_label);
closeButton = findViewById(R.id.close_button);
playerToolbar = findViewById(R.id.player_toolbar);
closeButton.setOnClickListener(v -> finish());
playerView.setOnClickListener(v -> toggleOverlay());
// For SurfaceView:
// surfaceView.setOnClickListener(v -> toggleOverlay());
}
```
---
## Phase 4: VLC Player Implementation Details
### 4.1 Initialize VLC with Custom Headers
**New Method: `startPlayback(String streamUrl)`**
```java
private void startPlayback(String streamUrl) {
try {
releasePlayer();
lastStreamUrl = streamUrl;
retryCount = 0;
// Create LibVLC instance with options
ArrayList<String> options = new ArrayList<>();
// Network options
options.add("--network-caching=1500");
options.add("--clock-jitter=0");
options.add("--clock-synchro=0");
// HTTP options for headers
options.add(":http-user-agent=" + USER_AGENT);
options.add(":http-referrer=" + "http://streamtp10.com/");
// SSL options (accept all certificates)
options.add("--no-xlib");
options.add(":rtsp-tcp");
options.add(":no-cert-check");
// Create LibVLC
libVlc = new LibVLC(this, options);
// Create MediaPlayer
mediaPlayer = new MediaPlayer(libVlc);
// Set up event listeners
setupMediaPlayerListeners();
// Create Media with custom headers
Media media = new Media(libVlc, android.net.Uri.parse(streamUrl));
// Add headers via Media options
Map<String, String> headers = new HashMap<>();
headers.put("Referer", "http://streamtp10.com/");
headers.put("User-Agent", USER_AGENT);
media.addOption(":http-user-agent=" + USER_AGENT);
media.addOption(":http-referrer=http://streamtp10.com/");
mediaPlayer.setMedia(media);
media.release();
// Set up video output
IVLCVout vout = mediaPlayer.getVLCVout();
if (playerView instanceof VLCVideoLayout) {
vout.setVideoView(playerView);
} else if (surfaceView != null) {
vout.setVideoView(surfaceView);
}
vout.attachViews();
// Start playback
mediaPlayer.play();
setOverlayVisible(false);
} catch (Exception e) {
showError("Error al inicializar reproductor: " + e.getMessage());
}
}
```
### 4.2 Player Event Listeners
**New Method: `setupMediaPlayerListeners()`**
```java
private void setupMediaPlayerListeners() {
// MediaPlayer.EventListener using the VLC event system
mediaPlayer.setEventListener(new MediaPlayer.EventListener() {
@Override
public void onEvent(MediaPlayer.Event event) {
switch (event.type) {
case MediaPlayer.Event.Playing:
// Equivalent to STATE_READY
runOnUiThread(() -> {
showLoading(false);
retryCount = 0;
});
break;
case MediaPlayer.Event.Buffering:
// Buffering state (0.0 to 1.0)
float bufferPercent = event.getBuffering();
runOnUiThread(() -> showLoading(bufferPercent < 1.0f));
break;
case MediaPlayer.Event.EncounteredError:
// Error occurred
runOnUiThread(() -> handlePlaybackError("Error de reproducción VLC"));
break;
case MediaPlayer.Event.EndReached:
// Stream ended
runOnUiThread(() -> finish());
break;
case MediaPlayer.Event.Stopped:
// Playback stopped
break;
case MediaPlayer.Event.Paused:
// Playback paused
break;
case MediaPlayer.Event.Opening:
// Stream opening
runOnUiThread(() -> showLoading(true));
break;
}
}
});
}
```
### 4.3 Error Handling with Retry
**New Method: `handlePlaybackError(String errorMessage)`**
```java
private void handlePlaybackError(String errorMsg) {
boolean isRetryableError =
errorMsg.contains("404") ||
errorMsg.contains("403") ||
errorMsg.contains("timeout") ||
errorMsg.contains("Network") ||
errorMsg.contains("Connection");
if (isRetryableError && retryCount < MAX_RETRIES) {
retryCount++;
runOnUiThread(() -> {
showLoading(true);
showError("Error de conexión. Reintentando... (" + retryCount + "/" + MAX_RETRIES + ")");
});
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> {
if (lastStreamUrl != null) {
startPlayback(lastStreamUrl);
} else {
loadChannel();
}
}, 2000);
} else {
String finalMessage = "Error al reproducir: " + errorMsg;
if (retryCount >= MAX_RETRIES) {
finalMessage += "\n\nSe agotaron los reintentos (" + MAX_RETRIES + ").";
}
showError(finalMessage);
}
}
```
### 4.4 Player Lifecycle Methods
**Replace releasePlayer() (lines 257-262):**
```java
private void releasePlayer() {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.getVLCVout().detachViews();
mediaPlayer.release();
mediaPlayer = null;
}
if (libVlc != null) {
libVlc.release();
libVlc = null;
}
}
```
**Update lifecycle methods:**
```java
@Override
protected void onStart() {
super.onStart();
if (mediaPlayer != null && !mediaPlayer.isPlaying()) {
mediaPlayer.play();
} else if (channelUrl != null && libVlc == null) {
loadChannel();
}
}
@Override
protected void onResume() {
super.onResume();
if (mediaPlayer != null) {
mediaPlayer.play();
}
}
@Override
protected void onPause() {
super.onPause();
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
mediaPlayer.pause();
}
}
@Override
protected void onStop() {
super.onStop();
// Keep player for quick resume, don't release
}
@Override
protected void onDestroy() {
super.onDestroy();
releasePlayer();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
```
---
## Phase 5: DRM Support (ClearKey)
### ClearKey DRM Implementation Example
**New Class: `VlcDrmManager.java`**
**Location**: `app/src/main/java/com/streamplayer/VlcDrmManager.java`
```java
package com.streamplayer;
import org.videolan.libvlc.Media;
import java.util.HashMap;
import java.util.Map;
/**
* Handles DRM configuration for VLC Media Player
* Supports ClearKey DRM for protected streaming services
*/
public class VlcDrmManager {
// ClearKey DRM configuration
private static final String CLEARKEY_KEY_SYSTEM = "org.w3.clearkey";
/**
* Configure ClearKey DRM for a Media object
* @param media The VLC Media object
* @param keyId The key ID (extracted from manifest or license server)
* @param key The content key
*/
public static void configureClearKey(Media media, String keyId, String key) {
if (media == null || keyId == null || key == null) {
return;
}
// VLC uses a specific format for ClearKey
// Format: keyid:key
String keyPair = keyId + ":" + key;
media.addOption(":demux=avformat");
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
media.addOption(":key=" + keyPair);
}
/**
* Configure ClearKey DRM with multiple keys
* @param media The VLC Media object
* @param keys Map of keyId -> key pairs
*/
public static void configureClearKey(Media media, Map<String, String> keys) {
if (media == null || keys == null || keys.isEmpty()) {
return;
}
media.addOption(":demux=avformat");
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
for (Map.Entry<String, String> entry : keys.entrySet()) {
String keyPair = entry.getKey() + ":" + entry.getValue();
media.addOption(":key=" + keyPair);
}
}
/**
* Configure Widevine DRM (for reference, if needed later)
* VLC supports Widevine via specific options
*/
public static void configureWidevine(Media media, String drmServerUrl) {
if (media == null || drmServerUrl == null) {
return;
}
media.addOption(":drm=widevine");
media.addOption(":aes-key=" + drmServerUrl);
}
}
```
### Extracting ClearKey Keys from Stream
**Update `StreamUrlResolver.java` to extract DRM info:**
Add this method to `StreamUrlResolver`:
```java
/**
* Extract ClearKey DRM keys from JSON in HTML
* @return Map of keyId -> key pairs, or null if no DRM found
*/
public static Map<String, String> extractClearKeyKeys(String html) {
Map<String, String> keys = new HashMap<>();
try {
// Pattern to find ClearKey key IDs and keys
// Common patterns in protected streaming services
Pattern clearkeyPattern = Pattern.compile(
"\"kid\"\\s*:\\s*\"([^\"]+)\".*?\"k\"\\s*:\\s*\"([^\"]+)\"",
Pattern.DOTALL
);
Matcher matcher = clearkeyPattern.matcher(html);
while (matcher.find()) {
String keyId = matcher.group(1);
String key = matcher.group(2);
keys.put(keyId, key);
}
// Alternative pattern for JWPlayer with DRM
Pattern jwDrmPattern = Pattern.compile(
"\"drm\"\\s*:\\s*\\{[^}]*\"clearkey\"\\s*:\\s*\\{[^}]*\"keyId\"\\s*:\\s*\"([^\"]+)\"[^}]*\"key\"\\s*:\\s*\"([^\"]+)\"",
Pattern.DOTALL
);
Matcher jwMatcher = jwDrmPattern.matcher(html);
while (jwMatcher.find()) {
String keyId = jwMatcher.group(1);
String key = jwMatcher.group(2);
keys.put(keyId, key);
}
} catch (Exception e) {
// Return empty map on error
}
return keys.isEmpty() ? null : keys;
}
```
### Using DRM in PlayerActivity
**Modify `startPlayback()` to handle DRM:**
```java
// After loading stream URL, also check for DRM keys
new Thread(() -> {
try {
String resolvedUrl = StreamUrlResolver.resolve(channelUrl);
Map<String, String> drmKeys = StreamUrlResolver.extractClearKeyKeys(html); // Need to modify resolver to also return HTML
runOnUiThread(() -> startPlayback(resolvedUrl, drmKeys));
} catch (IOException e) {
runOnUiThread(() -> showError("No se pudo conectar con el canal: " + e.getMessage()));
}
}).start();
private void startPlayback(String streamUrl, Map<String, String> drmKeys) {
// ... existing VLC setup code ...
Media media = new Media(libVlc, android.net.Uri.parse(streamUrl));
// Add headers
media.addOption(":http-user-agent=" + USER_AGENT);
media.addOption(":http-referrer=http://streamtp10.com/");
// Add DRM if available
if (drmKeys != null && !drmKeys.isEmpty()) {
VlcDrmManager.configureClearKey(media, drmKeys);
}
// ... rest of the setup ...
}
```
---
## Phase 6: Additional Files
### New File: `VlcPlayerConfig.java`
**Location**: `app/src/main/java/com/streamplayer/VlcPlayerConfig.java`
```java
package com.streamplayer;
/**
* Configuration constants for VLC Player
*/
public class VlcPlayerConfig {
// Network caching (ms)
public static final int NETWORK_CACHING = 1500;
// Live streaming caching (ms)
public static final int LIVE_CACHING = 5000;
// User Agent
public static final String USER_AGENT =
"Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36";
// Hardware acceleration options
public static final String HW_ACCELERATION = "automatic"; // or "full", "none", "decoding", "rendering"
// Chroma format
public static final String CHROMA = "RV32"; // or YV12, NV12
// Audio output
public static final String AUDIO_OUTPUT = "opensles";
}
```
---
## Phase 7: Summary of File Changes
| File Path | Change Type | Description |
|-----------|-------------|-------------|
| `app/build.gradle` | Modify | Remove Media3 deps, add VLC SDK |
| `app/src/main/res/layout/activity_player.xml` | Modify | Replace PlayerView with VLCVideoLayout |
| `app/src/main/java/com/streamplayer/PlayerActivity.java` | Rewrite | Complete VLC integration |
| `app/src/main/java/com/streamplayer/VlcDrmManager.java` | New | DRM configuration handler |
| `app/src/main/java/com/streamplayer/VlcPlayerConfig.java` | New | VLC configuration constants |
| `app/src/main/java/com/streamplayer/StreamUrlResolver.java` | Modify | Add DRM key extraction |
---
## Phase 8: VLC-Specific Notes
### HTTP Headers in VLC
VLC handles HTTP headers differently than ExoPlayer:
- Headers are set via Media.addOption() with colon prefix
- Format: `:http-header-name=value`
- Common options:
- `:http-user-agent=<value>`
- `:http-referrer=<value>`
- `:http-cookie=<value>`
### VLC Events vs ExoPlayer States
| ExoPlayer State | VLC Event |
|----------------|-----------|
| STATE_IDLE | N/A (not initialized) |
| STATE_BUFFERING | Event.Buffering |
| STATE_READY | Event.Playing |
| STATE_ENDED | Event.EndReached |
### DRM Support Comparison
| Feature | ExoPlayer | VLC |
|---------|-----------|-----|
| Widevine | Native | Limited |
| ClearKey | Via DRM module | Via libavformat |
| PlayReady | Native | Limited |
| FairPlay | No | Limited |
---
## Phase 9: Testing Checklist
1. [ ] Basic HLS stream playback
2. [ ] HTTP headers (Referer, User-Agent) applied correctly
3. [ ] Loading indicator shows/hides correctly
4. [ ] Error messages display properly
5. [ ] Retry logic works on connection failure
6. [ ] Screen stays on during playback
7. [ ] Overlay toggle works on tap
8. [ ] Close button returns to main activity
9. [ ] App handles pause/resume correctly
10. [ ] Memory leaks checked (no retained VLC instances)
11. [ ] DRM streams play correctly
12. [ ] SSL certificate bypass works
---
## Phase 10: Fallback Strategy
If VLC doesn't work as expected, consider:
1. **Hybrid approach**: Keep ExoPlayer as fallback, use VLC for DRM-only streams
2. **Alternative libraries**:
- Vitamio (deprecated but still works)
- NKD-Player (wrapper around FFmpeg)
- Build custom FFmpeg integration
3. **Webview approach**: Use embedded browser for DRM content
---
## Appendix: VLC SDK Documentation Links
- VLC Android SDK: https://code.videolan.org/videolan/vlc-android
- VLC LibVLC API: https://code.videolan.org/videolan/vlc-android/-/tree/master/libvlc
- VLC Wiki on Android: https://wiki.videolan.org/AndroidCompile
- ClearKey DRM spec: https://w3c.github.io/encrypted-media/format-registry/initdata/cenc.html

View File

@@ -8,9 +8,8 @@ android {
applicationId "com.streamplayer"
minSdk 21
targetSdk 35
versionCode 100200
versionName "11.0.0"
buildConfigField "String", "DEVICE_REGISTRY_URL", '"http://194.163.191.200:4000"'
versionCode 100201
versionName "11.0.1"
}
buildTypes {
@@ -49,10 +48,9 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.media3:media3-exoplayer:1.4.1'
implementation 'androidx.media3:media3-exoplayer-hls:1.4.1'
implementation 'androidx.media3:media3-exoplayer-dash:1.4.1'
implementation 'androidx.media3:media3-ui:1.4.1'
// VLC Player para reproduccion de video (soporte DRM mejorado)
implementation 'org.videolan.android:libvlc-all:3.4.4'
implementation 'androidx.media3:media3-datasource-okhttp:1.4.1'
// OkHttp con DNS over HTTPS (para StreamUrlResolver)
implementation 'com.squareup.okhttp3:okhttp:4.12.0'

View File

@@ -7,21 +7,37 @@ import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ChannelViewHolder> {
public class ChannelAdapter extends ListAdapter<StreamChannel, ChannelAdapter.ChannelViewHolder> {
public interface OnChannelClickListener {
void onChannelClick(StreamChannel channel);
}
private final List<StreamChannel> channels = new ArrayList<>();
private static final DiffUtil.ItemCallback<StreamChannel> DIFF_CALLBACK =
new DiffUtil.ItemCallback<StreamChannel>() {
@Override
public boolean areItemsTheSame(@NonNull StreamChannel oldItem, @NonNull StreamChannel newItem) {
return oldItem.getPageUrl().equals(newItem.getPageUrl());
}
@Override
public boolean areContentsTheSame(@NonNull StreamChannel oldItem, @NonNull StreamChannel newItem) {
return oldItem.getName().equals(newItem.getName())
&& oldItem.getPageUrl().equals(newItem.getPageUrl());
}
};
private final OnChannelClickListener listener;
public ChannelAdapter(OnChannelClickListener listener) {
super(DIFF_CALLBACK);
this.listener = listener;
}
@@ -35,7 +51,7 @@ public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ChannelV
@Override
public void onBindViewHolder(@NonNull ChannelViewHolder holder, int position) {
StreamChannel channel = channels.get(position);
StreamChannel channel = getItem(position);
holder.name.setText(channel.getName());
holder.icon.setImageResource(R.drawable.ic_channel_default);
holder.itemView.setOnClickListener(v -> {
@@ -52,7 +68,7 @@ public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ChannelV
@Override
public int getItemCount() {
return channels.size();
return super.getItemCount();
}
static class ChannelViewHolder extends RecyclerView.ViewHolder {
@@ -67,10 +83,10 @@ public class ChannelAdapter extends RecyclerView.Adapter<ChannelAdapter.ChannelV
}
public void submitList(List<StreamChannel> newChannels) {
channels.clear();
if (newChannels != null) {
channels.addAll(newChannels);
if (newChannels == null) {
super.submitList(null);
return;
}
notifyDataSetChanged();
super.submitList(new ArrayList<>(newChannels));
}
}

View File

@@ -8,6 +8,13 @@ import java.util.List;
public final class ChannelRepository {
private static final Comparator<StreamChannel> CHANNEL_NAME_COMPARATOR =
new Comparator<StreamChannel>() {
@Override
public int compare(StreamChannel left, StreamChannel right) {
return String.CASE_INSENSITIVE_ORDER.compare(left.getName(), right.getName());
}
};
private static final List<StreamChannel> CHANNELS = createChannels();
private static List<StreamChannel> createChannels() {
@@ -79,7 +86,7 @@ public final class ChannelRepository {
new StreamChannel("FUTV", "http://streamtp10.com/global2.php?stream=futv"),
new StreamChannel("LaLiga Hypermotion", "http://streamtp10.com/global2.php?stream=laligahypermotion")
));
channels.sort(Comparator.comparing(StreamChannel::getName, String.CASE_INSENSITIVE_ORDER));
Collections.sort(channels, CHANNEL_NAME_COMPARATOR);
return Collections.unmodifiableList(channels);
}

View File

@@ -1,169 +0,0 @@
package com.streamplayer;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* Informa al dashboard qué dispositivos tienen instalada la app y permite bloquearlos remotamente.
*/
public class DeviceRegistry {
public interface Callback {
void onAllowed();
void onBlocked(String reason, String tokenPart);
void onError(String message);
}
private static final String TAG = "DeviceRegistry";
private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
private final Context appContext;
private final OkHttpClient httpClient;
private final ExecutorService executorService;
private final Handler mainHandler = new Handler(Looper.getMainLooper());
public DeviceRegistry(Context context) {
this.appContext = context.getApplicationContext();
// Usar NetworkUtils para obtener cliente con DNS over HTTPS configurado
this.httpClient = NetworkUtils.getClient();
this.executorService = Executors.newSingleThreadExecutor();
}
public void syncDevice(Callback callback) {
if (TextUtils.isEmpty(BuildConfig.DEVICE_REGISTRY_URL)) {
postAllowed(callback);
return;
}
executorService.execute(() -> {
try {
JSONObject payload = new JSONObject();
payload.put("deviceId", getDeviceId());
payload.put("deviceName", Build.MODEL);
payload.put("model", Build.MODEL);
payload.put("manufacturer", capitalize(Build.MANUFACTURER));
payload.put("osVersion", Build.VERSION.RELEASE + " (API " + Build.VERSION.SDK_INT + ")");
payload.put("appVersionName", BuildConfig.VERSION_NAME);
payload.put("appVersionCode", BuildConfig.VERSION_CODE);
String endpoint = sanitizeBaseUrl(BuildConfig.DEVICE_REGISTRY_URL) + "/api/devices/register";
RequestBody body = RequestBody.create(payload.toString(), JSON);
Request request = new Request.Builder()
.url(endpoint)
.post(body)
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful() || response.body() == null) {
throw new IOException("HTTP " + response.code());
}
String responseText = response.body().string();
// Validar que no sea HTML antes de parsear
if (responseText != null) {
String trimmed = responseText.trim();
if (trimmed.startsWith("<!") || trimmed.startsWith("<html")) {
throw new IOException("El servidor devolvió HTML en lugar de JSON");
}
}
JSONObject json = new JSONObject(responseText);
JSONObject deviceJson = json.optJSONObject("device");
JSONObject verificationJson = json.optJSONObject("verification");
boolean blocked = json.optBoolean("blocked", false);
String reason = json.optString("message");
if (TextUtils.isEmpty(reason) && deviceJson != null) {
reason = deviceJson.optString("notes", "");
}
String tokenPart = "";
if (verificationJson != null) {
boolean verificationRequired = verificationJson.optBoolean("required", false);
blocked = blocked || verificationRequired;
tokenPart = verificationJson.optString("clientTokenPart", "");
}
if (blocked) {
postBlocked(callback, reason, tokenPart);
} else {
postAllowed(callback);
}
}
} catch (IOException | JSONException e) {
Log.w(TAG, "Device sync error", e);
postError(callback, e.getMessage());
}
});
}
private String sanitizeBaseUrl(String base) {
if (TextUtils.isEmpty(base)) {
return "";
}
if (base.endsWith("/")) {
return base.substring(0, base.length() - 1);
}
return base;
}
private String getDeviceId() {
String id = Settings.Secure.getString(appContext.getContentResolver(),
Settings.Secure.ANDROID_ID);
if (TextUtils.isEmpty(id)) {
id = Build.MODEL + "-" + Build.BOARD + "-" + BuildConfig.VERSION_CODE;
}
return id;
}
private String capitalize(String value) {
if (TextUtils.isEmpty(value)) {
return "";
}
return value.substring(0, 1).toUpperCase(Locale.getDefault())
+ value.substring(1);
}
public void release() {
executorService.shutdownNow();
}
private void postAllowed(Callback callback) {
if (callback == null) {
return;
}
mainHandler.post(callback::onAllowed);
}
private void postBlocked(Callback callback, String reason, String tokenPart) {
if (callback == null) {
return;
}
String reasonText = reason == null ? "" : reason;
String token = tokenPart == null ? "" : tokenPart;
mainHandler.post(() -> callback.onBlocked(reasonText, token));
}
private void postError(Callback callback, String message) {
if (callback == null) {
return;
}
mainHandler.post(() -> callback.onError(message));
}
}

View File

@@ -6,29 +6,53 @@ import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class EventAdapter extends RecyclerView.Adapter<EventAdapter.EventViewHolder> {
public class EventAdapter extends ListAdapter<EventItem, EventAdapter.EventViewHolder> {
public interface OnEventClickListener {
void onEventClick(EventItem event);
}
private final List<EventItem> events = new ArrayList<>();
private static final DiffUtil.ItemCallback<EventItem> DIFF_CALLBACK =
new DiffUtil.ItemCallback<EventItem>() {
@Override
public boolean areItemsTheSame(@NonNull EventItem oldItem, @NonNull EventItem newItem) {
return oldItem.getPageUrl().equals(newItem.getPageUrl())
&& oldItem.getStartMillis() == newItem.getStartMillis();
}
@Override
public boolean areContentsTheSame(@NonNull EventItem oldItem, @NonNull EventItem newItem) {
return oldItem.getTitle().equals(newItem.getTitle())
&& oldItem.getTime().equals(newItem.getTime())
&& oldItem.getCategory().equals(newItem.getCategory())
&& oldItem.getStatus().equals(newItem.getStatus())
&& oldItem.getPageUrl().equals(newItem.getPageUrl())
&& oldItem.getChannelName().equals(newItem.getChannelName())
&& oldItem.getStartMillis() == newItem.getStartMillis();
}
};
private final OnEventClickListener listener;
public EventAdapter(OnEventClickListener listener) {
super(DIFF_CALLBACK);
this.listener = listener;
}
public void submitList(List<EventItem> newEvents) {
events.clear();
events.addAll(newEvents);
notifyDataSetChanged();
if (newEvents == null) {
super.submitList(null);
return;
}
super.submitList(new ArrayList<>(newEvents));
}
@NonNull
@@ -41,7 +65,7 @@ public class EventAdapter extends RecyclerView.Adapter<EventAdapter.EventViewHol
@Override
public void onBindViewHolder(@NonNull EventViewHolder holder, int position) {
EventItem event = events.get(position);
EventItem event = getItem(position);
holder.title.setText(event.getTitle());
holder.time.setText(event.getTime());
holder.channel.setText(event.getChannelName());
@@ -55,7 +79,7 @@ public class EventAdapter extends RecyclerView.Adapter<EventAdapter.EventViewHol
@Override
public int getItemCount() {
return events.size();
return super.getItemCount();
}
static class EventViewHolder extends RecyclerView.ViewHolder {

View File

@@ -8,16 +8,14 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import okhttp3.Request;
import okhttp3.Response;
@@ -28,6 +26,10 @@ public class EventRepository {
private static final String KEY_JSON = "json";
private static final String KEY_TIMESTAMP = "timestamp";
private static final long CACHE_DURATION = 24L * 60 * 60 * 1000; // 24 horas
private static final String ARGENTINA_TIMEZONE_ID = "America/Argentina/Buenos_Aires";
private static final TimeZone ARGENTINA_TIMEZONE = TimeZone.getTimeZone(ARGENTINA_TIMEZONE_ID);
private static final int ARGENTINA_OFFSET_HOURS = 2;
private static final long EVENT_ROLLOVER_WINDOW_MS = 12L * 60 * 60 * 1000;
// URL única para eventos (actualizado para evitar bloqueos de ISP)
private static final String EVENTS_URL = "http://streamtp10.com/eventos.json";
@@ -89,12 +91,6 @@ public class EventRepository {
throw new IOException("Respuesta vacía del servidor");
}
String contentType = response.header("Content-Type");
// Permitir json o text/plain (Raw de Gitea a veces es text/plain)
if (contentType != null && !contentType.contains("json") && !contentType.contains("text/plain")) {
// Aceptamos text/plain también por flexibilidad
}
String responseBody = response.body().string();
// Validar que no sea HTML
@@ -119,7 +115,6 @@ public class EventRepository {
JSONArray array = new JSONArray(json);
List<EventItem> events = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
for (int i = 0; i < array.length(); i++) {
JSONObject obj = array.getJSONObject(i);
@@ -129,19 +124,10 @@ public class EventRepository {
String status = obj.optString("status");
String link = obj.optString("link");
String normalized = normalizeLink(link);
// Ajustar hora: la web muestra hora de España, Argentina es +2 horas
String displayTime = time;
try {
if (time != null && !time.isEmpty()) {
LocalTime localTime = LocalTime.parse(time.trim(), formatter);
LocalTime adjustedTime = localTime.plusHours(2);
displayTime = adjustedTime.format(formatter);
}
} catch (DateTimeParseException ignored) {
}
long startMillis = parseEventTime(time);
EventSchedule schedule = computeEventSchedule(time);
String displayTime = schedule.displayTime;
long startMillis = schedule.startMillis;
events.add(new EventItem(title, displayTime, category, status, normalized, extractChannelName(link), startMillis));
}
return Collections.unmodifiableList(events);
@@ -164,28 +150,69 @@ public class EventRepository {
if (idx == -1) {
return "";
}
return link.substring(idx + 7).replace("_", " ").toUpperCase();
return link.substring(idx + 7).replace("_", " ").toUpperCase(Locale.ROOT);
}
private long parseEventTime(String time) {
if (time == null || time.isEmpty()) {
return -1;
private EventSchedule computeEventSchedule(String time) {
if (time == null || time.trim().isEmpty()) {
return new EventSchedule(time == null ? "" : time, -1L);
}
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime localTime = LocalTime.parse(time.trim(), formatter);
// Ajustar hora: la web muestra hora de España, Argentina es +2 horas
LocalTime adjustedTime = localTime.plusHours(2);
ZoneId zone = ZoneId.of("America/Argentina/Buenos_Aires");
LocalDate today = LocalDate.now(zone);
ZonedDateTime start = ZonedDateTime.of(LocalDateTime.of(today, adjustedTime), zone);
ZonedDateTime now = ZonedDateTime.now(zone);
if (start.isBefore(now.minusHours(12))) {
start = start.plusDays(1);
Calendar adjustedTime = parseAdjustedTime(time);
String displayTime = formatTime(adjustedTime);
Calendar now = Calendar.getInstance(ARGENTINA_TIMEZONE, Locale.US);
Calendar start = Calendar.getInstance(ARGENTINA_TIMEZONE, Locale.US);
start.set(Calendar.YEAR, now.get(Calendar.YEAR));
start.set(Calendar.MONTH, now.get(Calendar.MONTH));
start.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
start.set(Calendar.HOUR_OF_DAY, adjustedTime.get(Calendar.HOUR_OF_DAY));
start.set(Calendar.MINUTE, adjustedTime.get(Calendar.MINUTE));
start.set(Calendar.SECOND, 0);
start.set(Calendar.MILLISECOND, 0);
long nowMillis = now.getTimeInMillis();
long startMillis = start.getTimeInMillis();
if (startMillis < nowMillis - EVENT_ROLLOVER_WINDOW_MS) {
start.add(Calendar.DAY_OF_MONTH, 1);
startMillis = start.getTimeInMillis();
}
return start.toInstant().toEpochMilli();
} catch (DateTimeParseException e) {
return -1;
return new EventSchedule(displayTime, startMillis);
} catch (ParseException ignored) {
return new EventSchedule(time, -1L);
}
}
private Calendar parseAdjustedTime(String time) throws ParseException {
SimpleDateFormat parser = new SimpleDateFormat("HH:mm", Locale.US);
parser.setLenient(false);
parser.setTimeZone(ARGENTINA_TIMEZONE);
java.util.Date parsedDate = parser.parse(time.trim());
if (parsedDate == null) {
throw new ParseException("Hora inválida: " + time, 0);
}
Calendar adjusted = Calendar.getInstance(ARGENTINA_TIMEZONE, Locale.US);
adjusted.setTime(parsedDate);
adjusted.add(Calendar.HOUR_OF_DAY, ARGENTINA_OFFSET_HOURS);
return adjusted;
}
private String formatTime(Calendar calendar) {
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm", Locale.US);
formatter.setTimeZone(ARGENTINA_TIMEZONE);
return formatter.format(calendar.getTime());
}
private static final class EventSchedule {
final String displayTime;
final long startMillis;
EventSchedule(String displayTime, long startMillis) {
this.displayTime = displayTime;
this.startMillis = startMillis;
}
}
}

View File

@@ -1,22 +1,19 @@
package com.streamplayer;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -48,8 +45,6 @@ public class MainActivity extends AppCompatActivity {
private SectionEntry currentSection;
private UpdateManager updateManager;
private AlertDialog updateDialog;
private AlertDialog blockedDialog;
private DeviceRegistry deviceRegistry;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -112,28 +107,6 @@ public class MainActivity extends AppCompatActivity {
Toast.LENGTH_SHORT).show();
}
});
deviceRegistry = new DeviceRegistry(this);
deviceRegistry.syncDevice(new DeviceRegistry.Callback() {
@Override
public void onAllowed() {
// Device authorized, continue normally.
}
@Override
public void onBlocked(String reason, String tokenPart) {
showBlockedDialog(reason, tokenPart);
}
@Override
public void onError(String message) {
if (!TextUtils.isEmpty(message)) {
Toast.makeText(MainActivity.this,
getString(R.string.device_registry_error, message),
Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
@@ -150,15 +123,9 @@ public class MainActivity extends AppCompatActivity {
if (updateDialog != null && updateDialog.isShowing()) {
updateDialog.dismiss();
}
if (blockedDialog != null && blockedDialog.isShowing()) {
blockedDialog.dismiss();
}
if (updateManager != null) {
updateManager.release();
}
if (deviceRegistry != null) {
deviceRegistry.release();
}
}
private void selectSection(int index) {
@@ -272,7 +239,7 @@ public class MainActivity extends AppCompatActivity {
if (updateDialog != null && updateDialog.isShowing()) {
updateDialog.dismiss();
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.ThemeOverlay_StreamPlayer_AlertDialog)
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(mandatory ? R.string.update_required_title : R.string.update_available_title)
.setMessage(buildUpdateMessage(info))
.setPositiveButton(R.string.update_action_download,
@@ -286,7 +253,23 @@ public class MainActivity extends AppCompatActivity {
} else {
builder.setNegativeButton(R.string.update_action_later, null);
}
updateDialog = builder.show();
updateDialog = builder.create();
updateDialog.setOnShowListener(dialog -> {
int actionColor = ContextCompat.getColor(this, R.color.refresh_button_focused);
Button positive = updateDialog.getButton(AlertDialog.BUTTON_POSITIVE);
Button neutral = updateDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
Button negative = updateDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
if (positive != null) {
positive.setTextColor(actionColor);
}
if (neutral != null) {
neutral.setTextColor(actionColor);
}
if (negative != null) {
negative.setTextColor(actionColor);
}
});
updateDialog.show();
}
private CharSequence buildUpdateMessage(UpdateManager.UpdateInfo info) {
@@ -333,59 +316,11 @@ public class MainActivity extends AppCompatActivity {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
try {
startActivity(intent);
} catch (Exception e) {
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.update_error_open_release, Toast.LENGTH_SHORT).show();
}
}
private void showBlockedDialog(String reason, String tokenPart) {
if (isFinishing()) {
return;
}
String finalReason = TextUtils.isEmpty(reason)
? getString(R.string.device_blocked_default_reason)
: reason;
if (blockedDialog != null && blockedDialog.isShowing()) {
blockedDialog.dismiss();
}
View dialogView = getLayoutInflater().inflate(R.layout.dialog_blocked, null);
TextView messageText = dialogView.findViewById(R.id.blocked_message_text);
View tokenContainer = dialogView.findViewById(R.id.blocked_token_container);
TextView tokenValue = dialogView.findViewById(R.id.blocked_token_value);
messageText.setText(getString(R.string.device_blocked_message, finalReason));
boolean hasToken = !TextUtils.isEmpty(tokenPart);
if (hasToken) {
tokenContainer.setVisibility(View.VISIBLE);
tokenValue.setText(tokenPart);
tokenValue.setOnClickListener(v -> copyTokenToClipboard(tokenPart));
} else {
tokenContainer.setVisibility(View.GONE);
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.ThemeOverlay_StreamPlayer_AlertDialog)
.setTitle(R.string.device_blocked_title)
.setView(dialogView)
.setCancelable(false)
.setPositiveButton(R.string.device_blocked_close,
(dialog, which) -> finish());
if (hasToken) {
builder.setNeutralButton(R.string.device_blocked_copy_token,
(dialog, which) -> copyTokenToClipboard(tokenPart));
}
blockedDialog = builder.create();
blockedDialog.show();
}
private void copyTokenToClipboard(String tokenPart) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard == null) {
Toast.makeText(this, R.string.device_blocked_copy_error, Toast.LENGTH_SHORT).show();
return;
}
ClipData data = ClipData.newPlainText("token", tokenPart);
clipboard.setPrimaryClip(data);
Toast.makeText(this, R.string.device_blocked_copy_success, Toast.LENGTH_SHORT).show();
}
private int getSpanCount() {
return getResources().getInteger(R.integer.channel_grid_span);
}
@@ -398,7 +333,12 @@ public class MainActivity extends AppCompatActivity {
List<StreamChannel> allChannels = ChannelRepository.getChannels();
for (StreamChannel channel : allChannels) {
String key = deriveGroupName(channel.getName());
grouped.computeIfAbsent(key, k -> new ArrayList<>()).add(channel);
List<StreamChannel> group = grouped.get(key);
if (group == null) {
group = new ArrayList<>();
grouped.put(key, group);
}
group.add(channel);
}
List<StreamChannel> espnChannels = grouped.remove("ESPN");

View File

@@ -1,7 +1,8 @@
package com.streamplayer;
import android.util.Log;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -19,8 +20,9 @@ import okhttp3.dnsoverhttps.DnsOverHttps;
* Utilidad centralizada para configuración de red.
* Fuerza DNS over HTTPS con fallback Google -> Cloudflare -> DNS del sistema.
*/
public class NetworkUtils {
public final class NetworkUtils {
private static final String TAG = "NetworkUtils";
private static final OkHttpClient CLIENT;
private static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
private static final String GOOGLE_DOH_URL = "https://dns.google/dns-query";
@@ -51,7 +53,7 @@ public class NetworkUtils {
}
};
final SSLContext sslContext = SSLContext.getInstance("SSL");
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
builder.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0]);
@@ -105,12 +107,15 @@ public class NetworkUtils {
} catch (Exception e) {
builder.dns(Dns.SYSTEM);
System.out.println("Error configurando DNS over HTTPS: " + e.getMessage());
Log.w(TAG, "Error configurando DNS over HTTPS", e);
}
CLIENT = builder.build();
}
private NetworkUtils() {
}
public static OkHttpClient getClient() {
return CLIENT;
}

View File

@@ -5,7 +5,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.StrictMode;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
@@ -13,19 +13,30 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.OptIn;
import androidx.appcompat.app.AppCompatActivity;
import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.datasource.DefaultHttpDataSource;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.HttpDataSource;
import androidx.media3.datasource.okhttp.OkHttpDataSource;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.hls.HlsMediaSource;
import androidx.media3.exoplayer.drm.DefaultDrmSessionManager;
import androidx.media3.exoplayer.drm.FrameworkMediaDrm;
import androidx.media3.exoplayer.drm.LocalMediaDrmCallback;
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.ui.PlayerView;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@OptIn(markerClass = UnstableApi.class)
public class PlayerActivity extends AppCompatActivity {
public static final String EXTRA_CHANNEL_NAME = "extra_channel_name";
@@ -45,7 +56,7 @@ public class PlayerActivity extends AppCompatActivity {
private String channelUrl;
private boolean overlayVisible = true;
private int retryCount = 0;
private String lastStreamUrl;
private StreamUrlResolver.ResolvedStream lastResolvedStream;
private String currentChannelPageUrl;
private boolean playbackStarted = false;
private boolean alternateSourceAttempted = false;
@@ -58,10 +69,6 @@ public class PlayerActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder().permitAll().build()
);
setContentView(R.layout.activity_player);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
@@ -119,14 +126,17 @@ public class PlayerActivity extends AppCompatActivity {
new Thread(() -> {
try {
String resolvedUrl = StreamUrlResolver.resolve(pageUrl);
Log.d(TAG, "Stream resuelto: " + resolvedUrl + " (req=" + requestGeneration + ")");
StreamUrlResolver.ResolvedStream resolvedStream = StreamUrlResolver.resolve(pageUrl);
Log.d(TAG, "Stream resuelto: " + resolvedStream.getStreamUrl()
+ " | mime=" + resolvedStream.getMimeType()
+ " | drm=" + resolvedStream.hasClearKey()
+ " (req=" + requestGeneration + ")");
runOnUiThread(() -> {
if (!isLatestResolveRequest(requestGeneration)) {
Log.d(TAG, "Ignorando resultado viejo (req=" + requestGeneration + ")");
return;
}
startPlayback(resolvedUrl);
startPlayback(resolvedStream);
});
} catch (IOException e) {
runOnUiThread(() -> {
@@ -156,28 +166,18 @@ public class PlayerActivity extends AppCompatActivity {
}
}
private void startPlayback(String streamUrl) {
private void startPlayback(StreamUrlResolver.ResolvedStream resolvedStream) {
try {
releasePlayer();
lastStreamUrl = streamUrl;
lastResolvedStream = resolvedStream;
retryCount = 0;
playbackStarted = false;
scheduleStartupTimeout();
Log.d(TAG, "Iniciando reproducción: " + streamUrl);
Log.d(TAG, "Iniciando reproducción: " + resolvedStream.getStreamUrl()
+ " | mime=" + resolvedStream.getMimeType()
+ " | drm=" + resolvedStream.hasClearKey());
DefaultHttpDataSource.Factory httpFactory = new DefaultHttpDataSource.Factory()
.setUserAgent(VlcPlayerConfig.USER_AGENT)
.setAllowCrossProtocolRedirects(true)
.setConnectTimeoutMs(15000)
.setReadTimeoutMs(20000);
Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", VlcPlayerConfig.USER_AGENT);
httpFactory.setDefaultRequestProperties(headers);
HlsMediaSource mediaSource = new HlsMediaSource.Factory(httpFactory)
.setAllowChunklessPreparation(true)
.createMediaSource(MediaItem.fromUri(Uri.parse(streamUrl)));
MediaSource mediaSource = buildMediaSource(resolvedStream);
player = new ExoPlayer.Builder(this).build();
playerView.setPlayer(player);
@@ -196,6 +196,85 @@ public class PlayerActivity extends AppCompatActivity {
}
}
private MediaSource buildMediaSource(StreamUrlResolver.ResolvedStream resolvedStream) {
HttpDataSource.Factory httpFactory = createHttpDataSourceFactory(currentChannelPageUrl);
MediaItem.Builder mediaItemBuilder = new MediaItem.Builder()
.setUri(Uri.parse(resolvedStream.getStreamUrl()))
.setMimeType(resolvedStream.getMimeType());
DefaultMediaSourceFactory mediaSourceFactory = new DefaultMediaSourceFactory(httpFactory);
if (resolvedStream.hasClearKey()) {
mediaItemBuilder.setDrmConfiguration(
new MediaItem.DrmConfiguration.Builder(C.CLEARKEY_UUID).build());
DefaultDrmSessionManager drmSessionManager = new DefaultDrmSessionManager.Builder()
.setUuidAndExoMediaDrmProvider(C.CLEARKEY_UUID, FrameworkMediaDrm.DEFAULT_PROVIDER)
.build(new LocalMediaDrmCallback(buildClearKeyLicenseResponse(
resolvedStream.getClearKeyIdHex(),
resolvedStream.getClearKeyHex())));
mediaSourceFactory.setDrmSessionManagerProvider(mediaItem -> drmSessionManager);
}
return mediaSourceFactory.createMediaSource(mediaItemBuilder.build());
}
private HttpDataSource.Factory createHttpDataSourceFactory(String pageUrl) {
Map<String, String> headers = new HashMap<>();
headers.put("User-Agent", VlcPlayerConfig.USER_AGENT);
headers.put("Accept", "*/*");
String origin = buildOrigin(pageUrl);
if (origin != null) {
headers.put("Origin", origin);
headers.put("Referer", origin + "/");
}
return new OkHttpDataSource.Factory(NetworkUtils.getClient())
.setUserAgent(VlcPlayerConfig.USER_AGENT)
.setDefaultRequestProperties(headers);
}
private String buildOrigin(String pageUrl) {
if (pageUrl == null || pageUrl.isEmpty()) {
return null;
}
Uri uri = Uri.parse(pageUrl);
if (uri.getScheme() == null || uri.getHost() == null) {
return null;
}
StringBuilder origin = new StringBuilder()
.append(uri.getScheme())
.append("://")
.append(uri.getHost());
if (uri.getPort() != -1) {
origin.append(":").append(uri.getPort());
}
return origin.toString();
}
private byte[] buildClearKeyLicenseResponse(String keyIdHex, String keyHex) {
String keyIdBase64Url = encodeBase64Url(hexToBytes(keyIdHex));
String keyBase64Url = encodeBase64Url(hexToBytes(keyHex));
String response = "{\"keys\":[{\"k\":\"" + keyBase64Url
+ "\",\"kid\":\"" + keyIdBase64Url
+ "\",\"kty\":\"oct\"}],\"type\":\"temporary\"}";
return response.getBytes(StandardCharsets.UTF_8);
}
private byte[] hexToBytes(String value) {
int length = value.length();
byte[] bytes = new byte[length / 2];
for (int i = 0; i < length; i += 2) {
bytes[i / 2] = (byte) Integer.parseInt(value.substring(i, i + 2), 16);
}
return bytes;
}
private String encodeBase64Url(byte[] value) {
return Base64.encodeToString(value, Base64.NO_WRAP | Base64.NO_PADDING | Base64.URL_SAFE);
}
private void setupPlayerListener() {
if (player == null) {
return;
@@ -261,7 +340,7 @@ public class PlayerActivity extends AppCompatActivity {
return;
}
String lower = errorMsg.toLowerCase();
String lower = errorMsg.toLowerCase(Locale.ROOT);
boolean isRetryableError =
lower.contains("404") ||
lower.contains("403") ||
@@ -275,12 +354,12 @@ public class PlayerActivity extends AppCompatActivity {
runOnUiThread(() -> {
showLoading(true);
errorMessage.setVisibility(View.VISIBLE);
errorMessage.setText("Error de conexión. Reintentando... (" + retryCount + "/" + VlcPlayerConfig.MAX_RETRIES + ")");
errorMessage.setText(getString(R.string.player_retrying, retryCount, VlcPlayerConfig.MAX_RETRIES));
});
mainHandler.postDelayed(() -> {
if (lastStreamUrl != null) {
startPlayback(lastStreamUrl);
if (lastResolvedStream != null) {
startPlayback(lastResolvedStream);
} else {
loadChannel();
}
@@ -406,6 +485,7 @@ public class PlayerActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
mainHandler.removeCallbacksAndMessages(null);
super.onDestroy();
releasePlayer();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

View File

@@ -2,36 +2,27 @@ package com.streamplayer;
import android.util.Base64;
import androidx.media3.common.MimeTypes;
import java.io.IOException;
import java.net.InetAddress;
import java.security.cert.X509Certificate;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import okhttp3.Dns;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.dnsoverhttps.DnsOverHttps;
/**
* Resuelve la URL real del stream extrayendo playbackURL de la página.
* Utiliza DNS over HTTPS (Google + Cloudflare) para evitar bloqueos.
* Soporta múltiples formatos de páginas y streams directos.
* Soporta JWPlayer con DRM ClearKey.
* Incluye fallback para páginas con JWPlayer y formatos ofuscados.
*/
public final class StreamUrlResolver {
@@ -43,13 +34,13 @@ public final class StreamUrlResolver {
private static final Pattern VIDEO_SOURCE_PATTERN =
Pattern.compile("<source[^>]+src=[\"']([^\"']+)[\"']");
// Patrón para URLs M3U8 en cualquier parte del HTML
private static final Pattern M3U8_URL_PATTERN =
Pattern.compile("(https?://[^\\s'\"<>]+\\.m3u8[^\\s'\"<>]*)");
// Patrón para URLs HLS/DASH en cualquier parte del HTML
private static final Pattern STREAM_MANIFEST_URL_PATTERN =
Pattern.compile("(https?://[^\\s'\"<>]+\\.(?:m3u8|mpd)[^\\s'\"<>]*)");
// Patrón para URLs de stream en comillas dobles o simples
private static final Pattern STREAM_URL_PATTERN =
Pattern.compile("['\"](https?://[^'\"<>\\s]+?\\.(?:m3u8|mp4|ts)[^'\"<>\\s]*)['\"]");
Pattern.compile("['\"](https?://[^'\"<>\\s]+?\\.(?:m3u8|mpd|mp4|ts)[^'\"<>\\s]*)['\"]");
// Patrón para file: o url: en JavaScript
private static final Pattern JS_URL_PATTERN =
@@ -58,7 +49,8 @@ public final class StreamUrlResolver {
// Patrón para JWPlayer sources con "file": "url"
private static final Pattern JWPLAYER_FILE_PATTERN =
Pattern.compile("\"file\"\\s*:\\s*\"([^\"]+\\.m3u8[^\"]*)\"");
Pattern.compile("\"file\"\\s*:\\s*\"([^\"]+\\.(?:m3u8|mpd)[^\"]*)\"",
Pattern.CASE_INSENSITIVE);
// Patrón para pares [indice, "base64"] del nuevo playbackURL ofuscado
private static final Pattern OBFUSCATED_PAIR_PATTERN =
@@ -73,107 +65,32 @@ public final class StreamUrlResolver {
Pattern.compile("function\\s+([A-Za-z_$][\\w$]*)\\s*\\(\\)\\s*\\{\\s*return\\s*(\\d+)\\s*;?\\s*\\}",
Pattern.DOTALL);
private static final String USER_AGENT = "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
// Patrón para IIFEs que calculan k con dos returns inline.
private static final Pattern INLINE_OBFUSCATED_K_PATTERN =
Pattern.compile("k\\s*=\\s*\\(function\\s+[A-Za-z_$][\\w$]*\\(\\)\\s*\\{\\s*return\\s*(\\d+)\\s*\\}\\)\\(\\)\\s*\\+\\s*\\(function\\s+[A-Za-z_$][\\w$]*\\(\\)\\s*\\{\\s*return\\s*(\\d+)\\s*\\}\\)\\(\\)",
Pattern.DOTALL);
private static final OkHttpClient CLIENT;
static {
OkHttpClient client = null;
try {
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[]{};
}
}
};
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.followRedirects(true)
.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
.hostnameVerifier((hostname, session) -> true);
OkHttpClient bootstrap = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0])
.hostnameVerifier((hostname, session) -> true)
.build();
final DnsOverHttps googleDns = new DnsOverHttps.Builder()
.client(bootstrap)
.url(HttpUrl.get("https://dns.google/dns-query"))
.bootstrapDnsHosts(
InetAddress.getByName("8.8.8.8"),
InetAddress.getByName("8.8.4.4"))
.includeIPv6(false)
.build();
final DnsOverHttps cloudflareDns = new DnsOverHttps.Builder()
.client(bootstrap)
.url(HttpUrl.get("https://cloudflare-dns.com/dns-query"))
.bootstrapDnsHosts(
InetAddress.getByName("1.1.1.1"),
InetAddress.getByName("1.0.0.1"))
.includeIPv6(false)
.build();
builder.dns(hostname -> {
try {
List<InetAddress> result = googleDns.lookup(hostname);
if (result != null && !result.isEmpty()) {
return result;
}
} catch (Exception ignored) {
}
try {
List<InetAddress> result = cloudflareDns.lookup(hostname);
if (result != null && !result.isEmpty()) {
return result;
}
} catch (Exception ignored) {
}
return Dns.SYSTEM.lookup(hostname);
});
client = builder.build();
} catch (Exception e) {
client = new OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.followRedirects(true)
.dns(Dns.SYSTEM)
.build();
}
CLIENT = client;
}
private static final Pattern CLEAR_KEY_HEX_PATTERN =
Pattern.compile("^[0-9a-fA-F]{32}$");
private StreamUrlResolver() {
}
public static String resolve(String pageUrl) throws IOException {
public static ResolvedStream resolve(String pageUrl) throws IOException {
// Primero verificar si la URL ya parece ser un stream directo
if (isDirectStreamUrl(pageUrl)) {
return pageUrl;
return ResolvedStream.fromUrl(pageUrl);
}
String html = downloadPage(pageUrl);
String trimmedHtml = html.trim();
// Si el contenido ya parece ser un stream M3U8, retornarlo directamente
if (html.startsWith("#EXTM3U") || html.startsWith("#EXT")) {
return pageUrl;
// Si el contenido ya es un manifiesto directo, reproducirlo como tal.
if (trimmedHtml.startsWith("#EXTM3U") || trimmedHtml.startsWith("#EXT")) {
return ResolvedStream.hls(pageUrl);
}
if (isDashManifest(trimmedHtml)) {
return ResolvedStream.dash(pageUrl);
}
// Intentar múltiples patrones de extracción
@@ -182,56 +99,56 @@ public final class StreamUrlResolver {
// 1. Patrón original: var playbackURL = "..."
streamUrl = extractWithPattern(html, PLAYBACK_URL_PATTERN);
if (isValidStreamUrl(streamUrl)) {
return streamUrl;
return ResolvedStream.fromUrl(streamUrl);
}
// 2. Patrón: <source src="...">
streamUrl = extractWithPattern(html, VIDEO_SOURCE_PATTERN);
if (isValidStreamUrl(streamUrl)) {
return streamUrl;
return ResolvedStream.fromUrl(streamUrl);
}
// 3. Patrón: URLs M3U8 directas
streamUrl = extractWithPattern(html, M3U8_URL_PATTERN);
// 3. Patrón: URLs HLS/DASH directas
streamUrl = extractWithPattern(html, STREAM_MANIFEST_URL_PATTERN);
if (isValidStreamUrl(streamUrl)) {
return streamUrl;
return ResolvedStream.fromUrl(streamUrl);
}
// 4. Patrón: URLs de stream en comillas
streamUrl = extractWithPattern(html, STREAM_URL_PATTERN);
if (isValidStreamUrl(streamUrl)) {
return streamUrl;
return ResolvedStream.fromUrl(streamUrl);
}
// 5. Patrón: JavaScript file: / url: / stream:
streamUrl = extractWithPattern(html, JS_URL_PATTERN);
if (isValidStreamUrl(streamUrl)) {
return streamUrl;
return ResolvedStream.fromUrl(streamUrl);
}
// 6. Patrón: JWPlayer "file": "url.m3u8" (para reproductores web y otros)
// 6. Patrón: JWPlayer "file": "url" (para reproductores web y otros)
streamUrl = extractWithPattern(html, JWPLAYER_FILE_PATTERN);
if (isValidStreamUrl(streamUrl)) {
return streamUrl;
return ResolvedStream.fromUrl(streamUrl);
}
// 7. Nuevo formato ofuscado: playbackURL generado con atob + fromCharCode
streamUrl = decodeObfuscatedPlaybackUrl(html);
if (isValidStreamUrl(streamUrl)) {
return streamUrl;
return ResolvedStream.fromUrl(streamUrl);
}
// Si no encontramos nada con patrones, intentar usar la URL original
// como stream directo (útil para URLs que ya son streams)
if (html.contains(".m3u8") || html.contains("stream") || html.contains("video")) {
return pageUrl;
// 8. Eventos "transmision*.php": DASH + ClearKey en variables ofuscadas.
ResolvedStream dashClearKeyStream = decodeDashClearKeyStream(html);
if (dashClearKeyStream != null) {
return dashClearKeyStream;
}
// Último recurso: si la URL viene de sudamericaplay.com o similares,
// intentar usarla directamente
if (pageUrl.contains("sudamericaplay.com") ||
pageUrl.contains("paramount")) {
return pageUrl;
return ResolvedStream.fromUrl(pageUrl);
}
// Si no encontramos la URL, mostrar un fragmento del HTML para debug
@@ -292,6 +209,64 @@ public final class StreamUrlResolver {
long k = valueA + valueB;
return decodePairs(extractEncodedPairs(script), k);
}
private static ResolvedStream decodeDashClearKeyStream(String html) {
if (html == null ||
!html.contains("\"type\": \"dash\"") ||
!html.contains("clearkey")) {
return null;
}
String dashUrl = decodeObfuscatedVariable(html, "_u");
String keyId = decodeObfuscatedVariable(html, "_ki");
String key = decodeObfuscatedVariable(html, "_k");
if (!isValidStreamUrl(dashUrl) ||
!isValidClearKeyHex(keyId) ||
!isValidClearKeyHex(key)) {
return null;
}
return ResolvedStream.dashClearKey(dashUrl, keyId, key);
}
private static String decodeObfuscatedVariable(String html, String variableName) {
String marker = "var " + variableName + "='';";
int start = html.indexOf(marker);
if (start < 0) {
return null;
}
int end = html.indexOf("var _", start + marker.length());
if (end < 0) {
end = html.indexOf("var data = jwplayer", start + marker.length());
}
if (end < 0) {
end = html.indexOf("</script>", start + marker.length());
}
if (end <= start) {
return null;
}
String block = html.substring(start, end);
Matcher kMatcher = INLINE_OBFUSCATED_K_PATTERN.matcher(block);
if (!kMatcher.find()) {
return null;
}
long k;
try {
k = Long.parseLong(kMatcher.group(1)) + Long.parseLong(kMatcher.group(2));
} catch (NumberFormatException e) {
return null;
}
return decodePairs(extractEncodedPairs(block), k);
}
private static List<EncodedPair> extractEncodedPairs(String script) {
List<EncodedPair> pairs = new ArrayList<>();
Matcher pairMatcher = OBFUSCATED_PAIR_PATTERN.matcher(script);
while (pairMatcher.find()) {
@@ -302,13 +277,21 @@ public final class StreamUrlResolver {
}
}
Collections.sort(pairs, new Comparator<EncodedPair>() {
@Override
public int compare(EncodedPair left, EncodedPair right) {
return Integer.compare(left.index, right.index);
}
});
return pairs;
}
private static String decodePairs(List<EncodedPair> pairs, long k) {
if (pairs.isEmpty()) {
return null;
}
Collections.sort(pairs, Comparator.comparingInt(pair -> pair.index));
StringBuilder decoded = new StringBuilder(pairs.size());
for (EncodedPair pair : pairs) {
byte[] decodedBytes;
try {
@@ -342,12 +325,23 @@ public final class StreamUrlResolver {
return null;
}
String url = decoded.toString().trim()
return decoded.toString().trim()
.replace("\\/", "/")
.replace("\\u0026", "&")
.replace("\\u002F", "/");
}
return isValidStreamUrl(url) ? url : null;
private static boolean isDashManifest(String body) {
if (body == null || body.isEmpty()) {
return false;
}
String lower = body.toLowerCase(Locale.ROOT);
return lower.startsWith("<mpd") ||
(lower.startsWith("<?xml") && lower.contains("<mpd"));
}
private static boolean isValidClearKeyHex(String value) {
return value != null && CLEAR_KEY_HEX_PATTERN.matcher(value).matches();
}
/**
@@ -357,10 +351,10 @@ public final class StreamUrlResolver {
if (url == null || url.isEmpty()) {
return false;
}
String lower = url.toLowerCase();
String lower = url.toLowerCase(Locale.ROOT);
return lower.contains(".m3u8") ||
lower.contains(".mpd") ||
lower.contains("stream") && lower.contains(".php") == false ||
(lower.contains("stream") && !lower.contains(".php")) ||
lower.endsWith(".mp4") ||
lower.endsWith(".ts");
}
@@ -390,36 +384,16 @@ public final class StreamUrlResolver {
return null;
}
/**
* Intenta determinar el tipo de contenido del HTML
*/
private static String getContentTypeFromHtml(String html) {
if (html == null || html.isEmpty()) {
return "unknown";
}
String trimmed = html.trim();
if (trimmed.startsWith("#EXTM3U") || trimmed.startsWith("#EXT")) {
return "m3u8";
}
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
return "json";
}
if (trimmed.startsWith("<")) {
return "html";
}
return "text";
}
private static String downloadPage(String pageUrl) throws IOException {
Request request = new Request.Builder()
.url(pageUrl)
.header("User-Agent", USER_AGENT)
.header("User-Agent", NetworkUtils.getUserAgent())
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.header("Accept-Language", "es-ES,es;q=0.9,en;q=0.8")
.header("Referer", "http://streamtp10.com/")
.build();
try (Response response = CLIENT.newCall(request).execute()) {
try (Response response = NetworkUtils.getClient().newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Error HTTP " + response.code() + " al cargar la página del stream");
}
@@ -440,4 +414,76 @@ public final class StreamUrlResolver {
this.encodedValue = encodedValue;
}
}
public static final class ResolvedStream {
private final String streamUrl;
private final String mimeType;
private final String clearKeyIdHex;
private final String clearKeyHex;
private ResolvedStream(String streamUrl,
String mimeType,
String clearKeyIdHex,
String clearKeyHex) {
this.streamUrl = streamUrl;
this.mimeType = mimeType;
this.clearKeyIdHex = clearKeyIdHex;
this.clearKeyHex = clearKeyHex;
}
public static ResolvedStream fromUrl(String streamUrl) {
String lower = streamUrl.toLowerCase(Locale.ROOT);
if (lower.contains(".mpd")) {
return dash(streamUrl);
}
if (lower.contains(".mp4")) {
return progressive(streamUrl, MimeTypes.VIDEO_MP4);
}
if (lower.contains(".ts")) {
return progressive(streamUrl, MimeTypes.VIDEO_MP2T);
}
return hls(streamUrl);
}
public static ResolvedStream hls(String streamUrl) {
return new ResolvedStream(streamUrl, MimeTypes.APPLICATION_M3U8, null, null);
}
public static ResolvedStream dash(String streamUrl) {
return new ResolvedStream(streamUrl, MimeTypes.APPLICATION_MPD, null, null);
}
public static ResolvedStream dashClearKey(String streamUrl,
String clearKeyIdHex,
String clearKeyHex) {
return new ResolvedStream(streamUrl,
MimeTypes.APPLICATION_MPD,
clearKeyIdHex,
clearKeyHex);
}
public static ResolvedStream progressive(String streamUrl, String mimeType) {
return new ResolvedStream(streamUrl, mimeType, null, null);
}
public String getStreamUrl() {
return streamUrl;
}
public String getMimeType() {
return mimeType;
}
public String getClearKeyIdHex() {
return clearKeyIdHex;
}
public String getClearKeyHex() {
return clearKeyHex;
}
public boolean hasClearKey() {
return clearKeyIdHex != null && clearKeyHex != null;
}
}
}

View File

@@ -20,6 +20,7 @@ import android.util.Log;
import android.widget.Toast;
import androidx.core.content.FileProvider;
import androidx.core.content.ContextCompat;
import org.json.JSONArray;
import org.json.JSONException;
@@ -34,7 +35,6 @@ import java.util.concurrent.Executors;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Request;
import okhttp3.Response;
/**
@@ -117,7 +117,7 @@ public class UpdateManager {
return;
}
File targetDir = appContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
if (targetDir == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (targetDir == null) {
targetDir = appContext.getExternalFilesDir(null);
}
if (targetDir == null) {
@@ -273,21 +273,27 @@ public class UpdateManager {
if (assets == null) {
return null;
}
JSONObject fallback = null;
JSONObject firstApk = null;
JSONObject debugApk = null;
for (int i = 0; i < assets.length(); i++) {
JSONObject asset = assets.optJSONObject(i);
if (asset == null) {
continue;
}
if (fallback == null) {
fallback = asset;
}
String name = asset.optString("name", "").toLowerCase(Locale.US);
if (name.endsWith(".apk")) {
return asset;
if (name.contains("release")) {
return asset;
}
if (firstApk == null) {
firstApk = asset;
}
if (name.contains("debug") && debugApk == null) {
debugApk = asset;
}
}
}
return fallback;
return firstApk != null ? firstApk : debugApk;
}
private String deriveVersionName(String tagName, String fallback) {
@@ -363,7 +369,12 @@ public class UpdateManager {
}
downloadReceiver = new DownloadReceiver();
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
appContext.registerReceiver(downloadReceiver, filter);
ContextCompat.registerReceiver(
appContext,
downloadReceiver,
filter,
ContextCompat.RECEIVER_NOT_EXPORTED
);
}
private void unregisterDownloadReceiver() {
@@ -440,7 +451,10 @@ public class UpdateManager {
if (callback == null) {
return;
}
mainHandler.post(() -> callback.onError(message));
String safeMessage = TextUtils.isEmpty(message)
? appContext.getString(R.string.update_error_unknown)
: message;
mainHandler.post(() -> callback.onError(safeMessage));
}
private void showToast(String message) {
@@ -533,4 +547,3 @@ public class UpdateManager {
}
}
}

View File

@@ -1,66 +0,0 @@
package com.streamplayer;
import org.videolan.libvlc.Media;
import java.util.Map;
/**
* Handles DRM configuration for VLC Media Player
* Supports ClearKey DRM for protected streaming services
*/
public class VlcDrmManager {
// ClearKey DRM configuration
private static final String CLEARKEY_KEY_SYSTEM = "org.w3.clearkey";
/**
* Configure ClearKey DRM for a Media object
* @param media The VLC Media object
* @param keyId The key ID (extracted from manifest or license server)
* @param key The content key
*/
public static void configureClearKey(Media media, String keyId, String key) {
if (media == null || keyId == null || key == null) {
return;
}
// VLC uses a specific format for ClearKey
// Format: keyid:key
String keyPair = keyId + ":" + key;
media.addOption(":demux=avformat");
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
media.addOption(":key=" + keyPair);
}
/**
* Configure ClearKey DRM with multiple keys
* @param media The VLC Media object
* @param keys Map of keyId -> key pairs
*/
public static void configureClearKey(Media media, Map<String, String> keys) {
if (media == null || keys == null || keys.isEmpty()) {
return;
}
media.addOption(":demux=avformat");
media.addOption(":key-format=" + CLEARKEY_KEY_SYSTEM);
for (Map.Entry<String, String> entry : keys.entrySet()) {
String keyPair = entry.getKey() + ":" + entry.getValue();
media.addOption(":key=" + keyPair);
}
}
/**
* Configure Widevine DRM (for reference, if needed later)
* VLC supports Widevine via specific options
*/
public static void configureWidevine(Media media, String drmServerUrl) {
if (media == null || drmServerUrl == null) {
return;
}
media.addOption(":drm=widevine");
media.addOption(":aes-key=" + drmServerUrl);
}
}

View File

@@ -1,29 +1,14 @@
package com.streamplayer;
/**
* Configuration constants for VLC Player
*/
public class VlcPlayerConfig {
// Network caching (ms)
public static final int NETWORK_CACHING = 1500;
// Live streaming caching (ms)
public static final int LIVE_CACHING = 5000;
public final class VlcPlayerConfig {
// User Agent
public static final String USER_AGENT =
"Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36";
// Hardware acceleration
public static final String HW_ACCELERATION = "automatic";
// Chroma format
public static final String CHROMA = "RV32";
// Audio output
public static final String AUDIO_OUTPUT = "opensles";
// Maximum retries for playback
public static final int MAX_RETRIES = 3;
private VlcPlayerConfig() {
}
}

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#18d763" />
<corners android:radius="20dp" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#5522c1ff" />
<corners android:radius="20dp" />
<stroke
android:width="2dp"
android:color="#88FFFFFF" />
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#3322c1ff" />
<corners android:radius="20dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#222222" />
<corners android:radius="20dp" />
<stroke
android:width="1dp"
android:color="#44FFFFFF" />
</shape>
</item>
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 850 B

View File

@@ -34,7 +34,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Canal"
android:text="@string/player_channel_default"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold" />
@@ -43,7 +43,7 @@
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Elegir otro"
android:text="@string/player_action_choose_other"
android:textAllCaps="false" />
</LinearLayout>

View File

@@ -1,48 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/blocked_message_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/blocked_token_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:id="@+id/blocked_token_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/device_blocked_token_label"
android:textColor="@android:color/black"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/blocked_token_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="@android:color/transparent"
android:padding="8dp"
android:textColor="@android:color/black"
android:textIsSelectable="true"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
@@ -16,8 +17,8 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/app_name"
android:tint="@color/white"
android:src="@drawable/ic_channel_default" />
android:src="@drawable/ic_channel_default"
app:tint="@color/white" />
<TextView
android:id="@+id/channel_name"

View File

@@ -47,6 +47,7 @@
android:id="@+id/event_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:textColor="#18d763"
android:textSize="14sp"

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="channel_entries">
<item>Azteca Deportes</item>
<item>Canal 5 MX</item>
<item>Caliente TV MX</item>
<item>DAZN 1</item>
<item>DAZN 2</item>
<item>DAZN LaLiga</item>
<item>DSports</item>
<item>DSports 2</item>
<item>DSports Plus</item>
<item>ESPN</item>
</string-array>
</resources>

View File

@@ -1,13 +1,15 @@
<resources>
<string name="app_name">StreamPlayer</string>
<string name="home_tagline">Todo el deporte en un solo lugar</string>
<string name="section_channels">Canales</string>
<string name="section_events">Eventos</string>
<string name="section_all_channels">Todos los canales</string>
<string name="message_no_channels">No hay canales disponibles</string>
<string name="message_no_events">No hay eventos disponibles</string>
<string name="action_refresh">Actualizar</string>
<string name="message_events_error">No se pudieron cargar los eventos: %1$s</string>
<string name="player_channel_default">Canal</string>
<string name="player_action_choose_other">Elegir otro</string>
<string name="player_retrying">Error de conexión. Reintentando... (%1$d/%2$d)</string>
<string name="update_required_title">Actualización obligatoria</string>
<string name="update_available_title">Actualización disponible</string>
<string name="update_action_download">Actualizar</string>
@@ -22,6 +24,7 @@
<string name="update_release_notes_title">Novedades</string>
<string name="update_optional_hint">Puedes continuar usando la app, pero recomendamos instalar la actualización para obtener el mejor rendimiento.</string>
<string name="update_error_checking">No se pudo verificar actualizaciones (%1$s)</string>
<string name="update_error_unknown">Error desconocido</string>
<string name="update_error_open_release">No se pudo abrir el detalle de la versión</string>
<string name="update_error_empty_response">Respuesta vacía del servidor de releases</string>
<string name="update_error_http">Error de red (%1$d)</string>
@@ -37,14 +40,4 @@
<string name="update_error_install_intent">No se pudo abrir el instalador de paquetes</string>
<string name="update_notification_title">StreamPlayer %1$s</string>
<string name="update_notification_description">Descargando nueva versión</string>
<string name="device_blocked_title">Dispositivo bloqueado</string>
<string name="device_blocked_message">Este dispositivo fue bloqueado desde el panel de control. Motivo: %1$s</string>
<string name="device_blocked_default_reason">Sin motivo especificado.</string>
<string name="device_blocked_token_hint">Comparte este código con el administrador para solicitar acceso: %1$s</string>
<string name="device_blocked_token_label">Código de verificación</string>
<string name="device_blocked_close">Salir</string>
<string name="device_blocked_copy_token">Copiar código</string>
<string name="device_blocked_copy_success">Código copiado al portapapeles</string>
<string name="device_blocked_copy_error">No se pudo copiar el código</string>
<string name="device_registry_error">No se pudo registrar el dispositivo (%1$s)</string>
</resources>

View File

@@ -6,10 +6,4 @@
<item name="android:statusBarColor">@color/black</item>
<item name="android:navigationBarColor">@color/black</item>
</style>
<style name="ThemeOverlay.StreamPlayer.AlertDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/white</item>
<item name="colorAccent">@color/white</item>
</style>
</resources>

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample backup rules file; uncomment and customize as necessary.
See https://developer.android.com/guide/topics/data/autobackup
for details.
Note: This file is ignored for devices older that API 23, even
if they have auto backup available.
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->
<exclude domain="sharedpref" path="." />
</full-backup-content>

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!--
<include domain="file" path="."/>
<exclude domain="file" path="no_backup/"/>
-->
<exclude domain="sharedpref" path="." />
</cloud-backup>
<!--
<device-transfer>
<include domain="file" path="."/>
<exclude domain="file" path="no_backup/"/>
</device-transfer>
-->
</data-extraction-rules>

View File

@@ -12,7 +12,6 @@ allprojects {
repositories {
google()
mavenCentral()
maven { url "https://get.videolan.org/android/maven2/" }
}
}

View File

@@ -1,95 +0,0 @@
#!/bin/bash
# StreamPlayer APK Build Script
# Esta aplicación Android reproduce streaming usando DNS de Google
echo "=== StreamPlayer APK Build ==="
echo "URL: https://streamtpmedia.com/global2.php?stream=espn"
echo "DNS: 8.8.8.8, 8.8.4.4"
echo
# Crear APK básico con estructura Android
mkdir -p build/intermediates/classes/com/streamplayer
# Compilar archivos Kotlin (simulado para este demo)
echo "Compilando fuentes Kotlin..."
find app/src/main/java -name "*.kt" | while read file; do
echo "Compilando: $file"
done
# Copiar recursos
echo "Copiando recursos..."
cp -r app/src/main/res build/intermediates/
# Crear AndroidManifest.xml procesado
mkdir -p build/intermediates/manifests
cp app/src/main/AndroidManifest.xml build/intermediates/manifests/
# Crear APK structure
mkdir -p build/apk/lib
mkdir -p build/apk/res
mkdir -p build/apk/META-INF
# Copiar recursos al APK
cp -r build/intermediates/res/* build/apk/res/ 2>/dev/null || true
# Crear manifest simplificado para el APK
cat > build/apk/AndroidManifest.xml << 'EOF'
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.streamplayer" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="33"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:label="StreamPlayer" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity" android:exported="true"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
EOF
# Crear classes.dex (simulado)
echo "Creando classes.dex..."
echo "SIMULATED_DEX_FOR_STREAMPLAYER" > build/apk/classes.dex
# Crear resources.arsc (simulado)
echo "CREATED: $(date)" > build/apk/resources.arsc
# Crear APK usando zip
echo "Creando APK..."
cd build/apk
zip -r ../streamplayer.apk . > /dev/null
cd ../..
# Firmar APK (simulado)
echo "Firmando APK..."
echo "UNSIGNED_DEBUG_BUILD" >> build/streamplayer.apk
# Mover APK final
cp build/streamplayer.apk ./StreamPlayer.apk
echo
echo "✅ APK CREADO EXITOSAMENTE!"
echo "📁 Archivo: StreamPlayer.apk"
echo "📱 App: StreamPlayer - Reproductor con DNS Google"
echo "🌐 Stream: ESPN (vía DNS 8.8.8.8, 8.8.4.4)"
echo "🔐 Permisos: INTERNET, ACCESS_NETWORK_STATE"
echo
echo "Características:"
echo "• Reproducción de streaming HTTP/HTTPS"
echo "• Optimización DNS para streaming"
echo "• Interfaz fullscreen landscape"
echo "• ExoPlayer integrado"
echo "• Íconos personalizados"
echo
echo "Para instalar:"
echo "adb install StreamPlayer.apk"
echo
echo "⚠️ Nota: Este es un APK de demostración."
echo " Para producción, compílalo con Android Studio."
echo " La configuración DNS está implementada en DNSSetter.kt"

View File

@@ -1,4 +0,0 @@
{
"telegramBotToken": "123456:ABCDEF-TOKEN",
"telegramChatId": "123456789"
}

View File

@@ -1,267 +0,0 @@
[
{
"deviceId": "f91f2668e8dfb2a7",
"alias": "",
"deviceName": "SM-S928B",
"model": "SM-S928B",
"manufacturer": "Samsung",
"osVersion": "16 (API 36)",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-11-23T22:31:13.359Z",
"lastSeen": "2025-11-25T19:07:38.445Z",
"blocked": false,
"notes": "",
"installs": 22,
"ip": "181.23.253.20",
"country": "AR",
"verification": {
"clientPart": "1714c2bb93670c3f",
"adminPart": "9924c7049211c58c",
"status": "verified",
"createdAt": "2025-11-23T22:31:13.359Z",
"verifiedAt": "2025-11-23T22:33:11.942Z"
}
},
{
"deviceId": "c8ee9361c07a3245",
"alias": "",
"deviceName": "23113RKC6G",
"model": "23113RKC6G",
"manufacturer": "Xiaomi",
"osVersion": "15 (API 35)",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-11-23T23:19:29.464Z",
"lastSeen": "2025-11-23T23:21:02.377Z",
"blocked": false,
"notes": "",
"installs": 3,
"ip": "181.23.253.20",
"country": "AR",
"verification": {
"clientPart": "f7d5a364822457da",
"adminPart": "b4acb7da77b11ce9",
"status": "verified",
"createdAt": "2025-11-23T23:19:29.464Z",
"verifiedAt": "2025-11-23T23:20:49.579Z"
}
},
{
"deviceId": "c874876530da8f76",
"alias": "",
"deviceName": "2020/2021 UHD Android TV",
"model": "2020/2021 UHD Android TV",
"manufacturer": "TPV",
"osVersion": "11 (API 30)",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-11-24T18:53:40.668Z",
"lastSeen": "2025-11-25T01:33:56.790Z",
"blocked": false,
"notes": "",
"installs": 3,
"ip": "181.23.253.20",
"country": "AR",
"verification": {
"clientPart": "76139a364baeda9b",
"adminPart": "86601e7089416b57",
"status": "verified",
"createdAt": "2025-11-24T18:53:40.668Z",
"verifiedAt": "2025-11-24T18:54:52.788Z"
}
},
{
"deviceId": "879fe5ad6ac80e2d",
"alias": "",
"deviceName": "SM-S928B",
"model": "SM-S928B",
"manufacturer": "Samsung",
"osVersion": "16 (API 36)",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-11-25T19:08:38.948Z",
"lastSeen": "2025-12-23T20:41:59.972Z",
"blocked": false,
"notes": "",
"installs": 9,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "e512eb7d5c026e85",
"adminPart": "1891c4eec608a722",
"status": "verified",
"createdAt": "2025-11-25T19:08:38.948Z",
"verifiedAt": "2025-11-25T19:08:56.806Z"
}
},
{
"deviceId": "97a5c320c47e17ad",
"alias": "",
"deviceName": "Chromecast",
"model": "Chromecast",
"manufacturer": "Google",
"osVersion": "14 (API 34)",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-11-25T19:10:27.358Z",
"lastSeen": "2025-12-29T23:21:36.891Z",
"blocked": false,
"notes": "",
"installs": 26,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "f35ae98e27e9877c",
"adminPart": "e421a660ff38fc67",
"status": "verified",
"createdAt": "2025-11-25T19:10:27.358Z",
"verifiedAt": "2025-11-25T19:10:54.592Z"
}
},
{
"deviceId": "79a556d89cd9f783",
"alias": "",
"deviceName": "motorola edge 30",
"model": "motorola edge 30",
"manufacturer": "Motorola",
"osVersion": "13 (API 33)",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-11-25T19:29:17.916Z",
"lastSeen": "2025-12-14T20:26:50.664Z",
"blocked": false,
"notes": "",
"installs": 5,
"ip": "181.25.52.139",
"country": "AR",
"verification": {
"clientPart": "4aec5b0e2e1c782a",
"adminPart": "7a4bb228e3b5048c",
"status": "verified",
"createdAt": "2025-11-25T19:29:17.916Z",
"verifiedAt": "2025-11-25T19:30:11.849Z"
}
},
{
"deviceId": "309f9f56550fc16bf047d636",
"alias": "",
"deviceName": "WIN-J7S53EBK2BG",
"model": "Microsoft Windows 10.0.26100",
"manufacturer": "Microsoft",
"osVersion": "Microsoft Windows NT 10.0.26100.0",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-12-17T18:37:45.562Z",
"lastSeen": "2025-12-17T19:28:44.530Z",
"blocked": false,
"notes": "por boludo",
"installs": 21,
"ip": "181.25.52.139",
"country": "AR",
"verification": {
"clientPart": "60989c16f0ed61d9",
"adminPart": "c1befd758b4cd459",
"status": "verified",
"createdAt": "2025-12-17T18:37:45.562Z",
"verifiedAt": "2025-12-17T18:38:24.129Z"
},
"blockedAt": "2025-12-17T19:14:30.701Z"
},
{
"deviceId": "12c96524b10b1e15f5611b0a",
"alias": "",
"deviceName": "WIN-1F1PBAQI7PR",
"model": "Microsoft Windows 10.0.26100",
"manufacturer": "Microsoft",
"osVersion": "Microsoft Windows NT 10.0.26100.0",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-12-17T19:35:44.810Z",
"lastSeen": "2025-12-17T19:38:12.510Z",
"blocked": false,
"notes": "",
"installs": 2,
"ip": "181.25.52.139",
"country": "AR",
"verification": {
"clientPart": "d41b6a6bc639fe77",
"adminPart": "dab1fa74da2edab2",
"status": "verified",
"createdAt": "2025-12-17T19:35:44.810Z",
"verifiedAt": "2025-12-17T19:37:59.152Z"
}
},
{
"deviceId": "6623a19316ebbbc1570b31e2",
"alias": "",
"deviceName": "DESKTOP-TF8OENP",
"model": "Microsoft Windows 10.0.19045",
"manufacturer": "Microsoft",
"osVersion": "Microsoft Windows NT 10.0.19045.0",
"appVersionName": "9.4.6",
"appVersionCode": 94600,
"firstSeen": "2025-12-17T19:53:20.007Z",
"lastSeen": "2025-12-17T19:56:52.028Z",
"blocked": false,
"notes": "",
"installs": 4,
"ip": "190.55.131.98",
"country": "AR",
"verification": {
"clientPart": "e5ed2a5989a8e44a",
"adminPart": "21e79e6e83e662cf",
"status": "verified",
"createdAt": "2025-12-17T19:53:20.007Z",
"verifiedAt": "2025-12-17T19:53:43.017Z"
}
},
{
"deviceId": "8678935B-0B7A-41B0-B6E3-AB205073BE7F",
"alias": "",
"deviceName": "iPhone 17 Pro",
"model": "iPhone",
"manufacturer": "Apple",
"osVersion": "iOS 26.2",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-12-29T22:27:06.203Z",
"lastSeen": "2025-12-29T22:36:32.797Z",
"blocked": false,
"notes": "",
"installs": 3,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "fac4063d6b67ce57",
"adminPart": "667b10f28d37b534",
"status": "verified",
"createdAt": "2025-12-29T22:27:06.203Z",
"verifiedAt": "2025-12-29T22:30:37.120Z"
}
},
{
"deviceId": "FB4B39C0-A766-4A01-980E-763ACE9118A2",
"alias": "",
"deviceName": "iPhone 17 Pro",
"model": "iPhone",
"manufacturer": "Apple",
"osVersion": "iOS 26.2",
"appVersionName": "9.4.2",
"appVersionCode": 94200,
"firstSeen": "2025-12-29T22:40:54.202Z",
"lastSeen": "2025-12-29T23:04:30.334Z",
"blocked": false,
"notes": "",
"installs": 4,
"ip": "181.23.228.93",
"country": "AR",
"verification": {
"clientPart": "353df62e6d1faee3",
"adminPart": "648bd37e530033f7",
"status": "verified",
"createdAt": "2025-12-29T22:40:54.202Z",
"verifiedAt": "2025-12-29T22:44:27.529Z"
}
}
]

1
dashboard/node_modules/.bin/mime generated vendored
View File

@@ -1 +0,0 @@
../mime/cli.js

View File

@@ -1 +0,0 @@
../nodemon/bin/nodemon.js

View File

@@ -1 +0,0 @@
../touch/bin/nodetouch.js

1
dashboard/node_modules/.bin/semver generated vendored
View File

@@ -1 +0,0 @@
../semver/bin/semver.js

File diff suppressed because it is too large Load Diff

View File

@@ -1,243 +0,0 @@
1.3.8 / 2022-02-02
==================
* deps: mime-types@~2.1.34
- deps: mime-db@~1.51.0
* deps: negotiator@0.6.3
1.3.7 / 2019-04-29
==================
* deps: negotiator@0.6.2
- Fix sorting charset, encoding, and language with extra parameters
1.3.6 / 2019-04-28
==================
* deps: mime-types@~2.1.24
- deps: mime-db@~1.40.0
1.3.5 / 2018-02-28
==================
* deps: mime-types@~2.1.18
- deps: mime-db@~1.33.0
1.3.4 / 2017-08-22
==================
* deps: mime-types@~2.1.16
- deps: mime-db@~1.29.0
1.3.3 / 2016-05-02
==================
* deps: mime-types@~2.1.11
- deps: mime-db@~1.23.0
* deps: negotiator@0.6.1
- perf: improve `Accept` parsing speed
- perf: improve `Accept-Charset` parsing speed
- perf: improve `Accept-Encoding` parsing speed
- perf: improve `Accept-Language` parsing speed
1.3.2 / 2016-03-08
==================
* deps: mime-types@~2.1.10
- Fix extension of `application/dash+xml`
- Update primary extension for `audio/mp4`
- deps: mime-db@~1.22.0
1.3.1 / 2016-01-19
==================
* deps: mime-types@~2.1.9
- deps: mime-db@~1.21.0
1.3.0 / 2015-09-29
==================
* deps: mime-types@~2.1.7
- deps: mime-db@~1.19.0
* deps: negotiator@0.6.0
- Fix including type extensions in parameters in `Accept` parsing
- Fix parsing `Accept` parameters with quoted equals
- Fix parsing `Accept` parameters with quoted semicolons
- Lazy-load modules from main entry point
- perf: delay type concatenation until needed
- perf: enable strict mode
- perf: hoist regular expressions
- perf: remove closures getting spec properties
- perf: remove a closure from media type parsing
- perf: remove property delete from media type parsing
1.2.13 / 2015-09-06
===================
* deps: mime-types@~2.1.6
- deps: mime-db@~1.18.0
1.2.12 / 2015-07-30
===================
* deps: mime-types@~2.1.4
- deps: mime-db@~1.16.0
1.2.11 / 2015-07-16
===================
* deps: mime-types@~2.1.3
- deps: mime-db@~1.15.0
1.2.10 / 2015-07-01
===================
* deps: mime-types@~2.1.2
- deps: mime-db@~1.14.0
1.2.9 / 2015-06-08
==================
* deps: mime-types@~2.1.1
- perf: fix deopt during mapping
1.2.8 / 2015-06-07
==================
* deps: mime-types@~2.1.0
- deps: mime-db@~1.13.0
* perf: avoid argument reassignment & argument slice
* perf: avoid negotiator recursive construction
* perf: enable strict mode
* perf: remove unnecessary bitwise operator
1.2.7 / 2015-05-10
==================
* deps: negotiator@0.5.3
- Fix media type parameter matching to be case-insensitive
1.2.6 / 2015-05-07
==================
* deps: mime-types@~2.0.11
- deps: mime-db@~1.9.1
* deps: negotiator@0.5.2
- Fix comparing media types with quoted values
- Fix splitting media types with quoted commas
1.2.5 / 2015-03-13
==================
* deps: mime-types@~2.0.10
- deps: mime-db@~1.8.0
1.2.4 / 2015-02-14
==================
* Support Node.js 0.6
* deps: mime-types@~2.0.9
- deps: mime-db@~1.7.0
* deps: negotiator@0.5.1
- Fix preference sorting to be stable for long acceptable lists
1.2.3 / 2015-01-31
==================
* deps: mime-types@~2.0.8
- deps: mime-db@~1.6.0
1.2.2 / 2014-12-30
==================
* deps: mime-types@~2.0.7
- deps: mime-db@~1.5.0
1.2.1 / 2014-12-30
==================
* deps: mime-types@~2.0.5
- deps: mime-db@~1.3.1
1.2.0 / 2014-12-19
==================
* deps: negotiator@0.5.0
- Fix list return order when large accepted list
- Fix missing identity encoding when q=0 exists
- Remove dynamic building of Negotiator class
1.1.4 / 2014-12-10
==================
* deps: mime-types@~2.0.4
- deps: mime-db@~1.3.0
1.1.3 / 2014-11-09
==================
* deps: mime-types@~2.0.3
- deps: mime-db@~1.2.0
1.1.2 / 2014-10-14
==================
* deps: negotiator@0.4.9
- Fix error when media type has invalid parameter
1.1.1 / 2014-09-28
==================
* deps: mime-types@~2.0.2
- deps: mime-db@~1.1.0
* deps: negotiator@0.4.8
- Fix all negotiations to be case-insensitive
- Stable sort preferences of same quality according to client order
1.1.0 / 2014-09-02
==================
* update `mime-types`
1.0.7 / 2014-07-04
==================
* Fix wrong type returned from `type` when match after unknown extension
1.0.6 / 2014-06-24
==================
* deps: negotiator@0.4.7
1.0.5 / 2014-06-20
==================
* fix crash when unknown extension given
1.0.4 / 2014-06-19
==================
* use `mime-types`
1.0.3 / 2014-06-11
==================
* deps: negotiator@0.4.6
- Order by specificity when quality is the same
1.0.2 / 2014-05-29
==================
* Fix interpretation when header not in request
* deps: pin negotiator@0.4.5
1.0.1 / 2014-01-18
==================
* Identity encoding isn't always acceptable
* deps: negotiator@~0.4.0
1.0.0 / 2013-12-27
==================
* Genesis

View File

@@ -1,23 +0,0 @@
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,140 +0,0 @@
# accepts
[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][github-actions-ci-image]][github-actions-ci-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator).
Extracted from [koa](https://www.npmjs.com/package/koa) for general use.
In addition to negotiator, it allows:
- Allows types as an array or arguments list, ie `(['text/html', 'application/json'])`
as well as `('text/html', 'application/json')`.
- Allows type shorthands such as `json`.
- Returns `false` when no types match
- Treats non-existent headers as `*`
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```sh
$ npm install accepts
```
## API
```js
var accepts = require('accepts')
```
### accepts(req)
Create a new `Accepts` object for the given `req`.
#### .charset(charsets)
Return the first accepted charset. If nothing in `charsets` is accepted,
then `false` is returned.
#### .charsets()
Return the charsets that the request accepts, in the order of the client's
preference (most preferred first).
#### .encoding(encodings)
Return the first accepted encoding. If nothing in `encodings` is accepted,
then `false` is returned.
#### .encodings()
Return the encodings that the request accepts, in the order of the client's
preference (most preferred first).
#### .language(languages)
Return the first accepted language. If nothing in `languages` is accepted,
then `false` is returned.
#### .languages()
Return the languages that the request accepts, in the order of the client's
preference (most preferred first).
#### .type(types)
Return the first accepted type (and it is returned as the same text as what
appears in the `types` array). If nothing in `types` is accepted, then `false`
is returned.
The `types` array can contain full MIME types or file extensions. Any value
that is not a full MIME types is passed to `require('mime-types').lookup`.
#### .types()
Return the types that the request accepts, in the order of the client's
preference (most preferred first).
## Examples
### Simple type negotiation
This simple example shows how to use `accepts` to return a different typed
respond body based on what the client wants to accept. The server lists it's
preferences in order and will get back the best match between the client and
server.
```js
var accepts = require('accepts')
var http = require('http')
function app (req, res) {
var accept = accepts(req)
// the order of this list is significant; should be server preferred order
switch (accept.type(['json', 'html'])) {
case 'json':
res.setHeader('Content-Type', 'application/json')
res.write('{"hello":"world!"}')
break
case 'html':
res.setHeader('Content-Type', 'text/html')
res.write('<b>hello, world!</b>')
break
default:
// the fallback is text/plain, so no need to specify it above
res.setHeader('Content-Type', 'text/plain')
res.write('hello, world!')
break
}
res.end()
}
http.createServer(app).listen(3000)
```
You can test this out with the cURL program:
```sh
curl -I -H'Accept: text/html' http://localhost:3000/
```
## License
[MIT](LICENSE)
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master
[coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master
[github-actions-ci-image]: https://badgen.net/github/checks/jshttp/accepts/master?label=ci
[github-actions-ci-url]: https://github.com/jshttp/accepts/actions/workflows/ci.yml
[node-version-image]: https://badgen.net/npm/node/accepts
[node-version-url]: https://nodejs.org/en/download
[npm-downloads-image]: https://badgen.net/npm/dm/accepts
[npm-url]: https://npmjs.org/package/accepts
[npm-version-image]: https://badgen.net/npm/v/accepts

View File

@@ -1,238 +0,0 @@
/*!
* accepts
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var Negotiator = require('negotiator')
var mime = require('mime-types')
/**
* Module exports.
* @public
*/
module.exports = Accepts
/**
* Create a new Accepts object for the given req.
*
* @param {object} req
* @public
*/
function Accepts (req) {
if (!(this instanceof Accepts)) {
return new Accepts(req)
}
this.headers = req.headers
this.negotiator = new Negotiator(req)
}
/**
* Check if the given `type(s)` is acceptable, returning
* the best match when true, otherwise `undefined`, in which
* case you should respond with 406 "Not Acceptable".
*
* The `type` value may be a single mime type string
* such as "application/json", the extension name
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
* or array is given the _best_ match, if any is returned.
*
* Examples:
*
* // Accept: text/html
* this.types('html');
* // => "html"
*
* // Accept: text/*, application/json
* this.types('html');
* // => "html"
* this.types('text/html');
* // => "text/html"
* this.types('json', 'text');
* // => "json"
* this.types('application/json');
* // => "application/json"
*
* // Accept: text/*, application/json
* this.types('image/png');
* this.types('png');
* // => undefined
*
* // Accept: text/*;q=.5, application/json
* this.types(['html', 'json']);
* this.types('html', 'json');
* // => "json"
*
* @param {String|Array} types...
* @return {String|Array|Boolean}
* @public
*/
Accepts.prototype.type =
Accepts.prototype.types = function (types_) {
var types = types_
// support flattened arguments
if (types && !Array.isArray(types)) {
types = new Array(arguments.length)
for (var i = 0; i < types.length; i++) {
types[i] = arguments[i]
}
}
// no types, return all requested types
if (!types || types.length === 0) {
return this.negotiator.mediaTypes()
}
// no accept header, return first given type
if (!this.headers.accept) {
return types[0]
}
var mimes = types.map(extToMime)
var accepts = this.negotiator.mediaTypes(mimes.filter(validMime))
var first = accepts[0]
return first
? types[mimes.indexOf(first)]
: false
}
/**
* Return accepted encodings or best fit based on `encodings`.
*
* Given `Accept-Encoding: gzip, deflate`
* an array sorted by quality is returned:
*
* ['gzip', 'deflate']
*
* @param {String|Array} encodings...
* @return {String|Array}
* @public
*/
Accepts.prototype.encoding =
Accepts.prototype.encodings = function (encodings_) {
var encodings = encodings_
// support flattened arguments
if (encodings && !Array.isArray(encodings)) {
encodings = new Array(arguments.length)
for (var i = 0; i < encodings.length; i++) {
encodings[i] = arguments[i]
}
}
// no encodings, return all requested encodings
if (!encodings || encodings.length === 0) {
return this.negotiator.encodings()
}
return this.negotiator.encodings(encodings)[0] || false
}
/**
* Return accepted charsets or best fit based on `charsets`.
*
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
* an array sorted by quality is returned:
*
* ['utf-8', 'utf-7', 'iso-8859-1']
*
* @param {String|Array} charsets...
* @return {String|Array}
* @public
*/
Accepts.prototype.charset =
Accepts.prototype.charsets = function (charsets_) {
var charsets = charsets_
// support flattened arguments
if (charsets && !Array.isArray(charsets)) {
charsets = new Array(arguments.length)
for (var i = 0; i < charsets.length; i++) {
charsets[i] = arguments[i]
}
}
// no charsets, return all requested charsets
if (!charsets || charsets.length === 0) {
return this.negotiator.charsets()
}
return this.negotiator.charsets(charsets)[0] || false
}
/**
* Return accepted languages or best fit based on `langs`.
*
* Given `Accept-Language: en;q=0.8, es, pt`
* an array sorted by quality is returned:
*
* ['es', 'pt', 'en']
*
* @param {String|Array} langs...
* @return {Array|String}
* @public
*/
Accepts.prototype.lang =
Accepts.prototype.langs =
Accepts.prototype.language =
Accepts.prototype.languages = function (languages_) {
var languages = languages_
// support flattened arguments
if (languages && !Array.isArray(languages)) {
languages = new Array(arguments.length)
for (var i = 0; i < languages.length; i++) {
languages[i] = arguments[i]
}
}
// no languages, return all requested languages
if (!languages || languages.length === 0) {
return this.negotiator.languages()
}
return this.negotiator.languages(languages)[0] || false
}
/**
* Convert extnames to mime.
*
* @param {String} type
* @return {String}
* @private
*/
function extToMime (type) {
return type.indexOf('/') === -1
? mime.lookup(type)
: type
}
/**
* Check if mime is valid.
*
* @param {String} type
* @return {String}
* @private
*/
function validMime (type) {
return typeof type === 'string'
}

View File

@@ -1,47 +0,0 @@
{
"name": "accepts",
"description": "Higher-level content negotiation",
"version": "1.3.8",
"contributors": [
"Douglas Christopher Wilson <doug@somethingdoug.com>",
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
],
"license": "MIT",
"repository": "jshttp/accepts",
"dependencies": {
"mime-types": "~2.1.34",
"negotiator": "0.6.3"
},
"devDependencies": {
"deep-equal": "1.0.1",
"eslint": "7.32.0",
"eslint-config-standard": "14.1.1",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-markdown": "2.2.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.3.1",
"eslint-plugin-standard": "4.1.0",
"mocha": "9.2.0",
"nyc": "15.1.0"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"lint": "eslint .",
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-ci": "nyc --reporter=lcov --reporter=text npm test",
"test-cov": "nyc --reporter=html --reporter=text npm test"
},
"keywords": [
"content",
"negotiation",
"accept",
"accepts"
]
}

View File

@@ -1,15 +0,0 @@
The ISC License
Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com)
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@@ -1,87 +0,0 @@
anymatch [![Build Status](https://travis-ci.org/micromatch/anymatch.svg?branch=master)](https://travis-ci.org/micromatch/anymatch) [![Coverage Status](https://img.shields.io/coveralls/micromatch/anymatch.svg?branch=master)](https://coveralls.io/r/micromatch/anymatch?branch=master)
======
Javascript module to match a string against a regular expression, glob, string,
or function that takes the string as an argument and returns a truthy or falsy
value. The matcher can also be an array of any or all of these. Useful for
allowing a very flexible user-defined config to define things like file paths.
__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
Usage
-----
```sh
npm install anymatch
```
#### anymatch(matchers, testString, [returnIndex], [options])
* __matchers__: (_Array|String|RegExp|Function_)
String to be directly matched, string with glob patterns, regular expression
test, function that takes the testString as an argument and returns a truthy
value if it should be matched, or an array of any number and mix of these types.
* __testString__: (_String|Array_) The string to test against the matchers. If
passed as an array, the first element of the array will be used as the
`testString` for non-function matchers, while the entire array will be applied
as the arguments for function matchers.
* __options__: (_Object_ [optional]_) Any of the [picomatch](https://github.com/micromatch/picomatch#options) options.
* __returnIndex__: (_Boolean [optional]_) If true, return the array index of
the first matcher that that testString matched, or -1 if no match, instead of a
boolean result.
```js
const anymatch = require('anymatch');
const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ;
anymatch(matchers, 'path/to/file.js'); // true
anymatch(matchers, 'path/anyjs/baz.js'); // true
anymatch(matchers, 'path/to/foo.js'); // true
anymatch(matchers, 'path/to/bar.js'); // true
anymatch(matchers, 'bar.js'); // false
// returnIndex = true
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1
// any picomatc
// using globs to match directories and their children
anymatch('node_modules', 'node_modules'); // true
anymatch('node_modules', 'node_modules/somelib/index.js'); // false
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
const matcher = anymatch(matchers);
['foo.js', 'bar.js'].filter(matcher); // [ 'foo.js' ]
anymatch master*
```
#### anymatch(matchers)
You can also pass in only your matcher(s) to get a curried function that has
already been bound to the provided matching criteria. This can be used as an
`Array#filter` callback.
```js
var matcher = anymatch(matchers);
matcher('path/to/file.js'); // true
matcher('path/anyjs/baz.js', true); // 1
['foo.js', 'bar.js'].filter(matcher); // ['foo.js']
```
Changelog
----------
[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
- **v3.0:** Removed `startIndex` and `endIndex` arguments. Node 8.x-only.
- **v2.0:** [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
- **v1.2:** anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
for glob pattern matching. Issues with glob pattern matching should be
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
License
-------
[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)

View File

@@ -1,20 +0,0 @@
type AnymatchFn = (testString: string) => boolean;
type AnymatchPattern = string|RegExp|AnymatchFn;
type AnymatchMatcher = AnymatchPattern|AnymatchPattern[]
type AnymatchTester = {
(testString: string|any[], returnIndex: true): number;
(testString: string|any[]): boolean;
}
type PicomatchOptions = {dot: boolean};
declare const anymatch: {
(matchers: AnymatchMatcher): AnymatchTester;
(matchers: AnymatchMatcher, testString: null, returnIndex: true | PicomatchOptions): AnymatchTester;
(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number;
(matchers: AnymatchMatcher, testString: string|any[]): boolean;
}
export {AnymatchMatcher as Matcher}
export {AnymatchTester as Tester}
export default anymatch

View File

@@ -1,104 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
const picomatch = require('picomatch');
const normalizePath = require('normalize-path');
/**
* @typedef {(testString: string) => boolean} AnymatchFn
* @typedef {string|RegExp|AnymatchFn} AnymatchPattern
* @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
*/
const BANG = '!';
const DEFAULT_OPTIONS = {returnIndex: false};
const arrify = (item) => Array.isArray(item) ? item : [item];
/**
* @param {AnymatchPattern} matcher
* @param {object} options
* @returns {AnymatchFn}
*/
const createPattern = (matcher, options) => {
if (typeof matcher === 'function') {
return matcher;
}
if (typeof matcher === 'string') {
const glob = picomatch(matcher, options);
return (string) => matcher === string || glob(string);
}
if (matcher instanceof RegExp) {
return (string) => matcher.test(string);
}
return (string) => false;
};
/**
* @param {Array<Function>} patterns
* @param {Array<Function>} negPatterns
* @param {String|Array} args
* @param {Boolean} returnIndex
* @returns {boolean|number}
*/
const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
const isList = Array.isArray(args);
const _path = isList ? args[0] : args;
if (!isList && typeof _path !== 'string') {
throw new TypeError('anymatch: second argument must be a string: got ' +
Object.prototype.toString.call(_path))
}
const path = normalizePath(_path, false);
for (let index = 0; index < negPatterns.length; index++) {
const nglob = negPatterns[index];
if (nglob(path)) {
return returnIndex ? -1 : false;
}
}
const applied = isList && [path].concat(args.slice(1));
for (let index = 0; index < patterns.length; index++) {
const pattern = patterns[index];
if (isList ? pattern(...applied) : pattern(path)) {
return returnIndex ? index : true;
}
}
return returnIndex ? -1 : false;
};
/**
* @param {AnymatchMatcher} matchers
* @param {Array|string} testString
* @param {object} options
* @returns {boolean|number|Function}
*/
const anymatch = (matchers, testString, options = DEFAULT_OPTIONS) => {
if (matchers == null) {
throw new TypeError('anymatch: specify first argument');
}
const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
const returnIndex = opts.returnIndex || false;
// Early cache for matchers.
const mtchers = arrify(matchers);
const negatedGlobs = mtchers
.filter(item => typeof item === 'string' && item.charAt(0) === BANG)
.map(item => item.slice(1))
.map(item => picomatch(item, opts));
const patterns = mtchers
.filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG))
.map(matcher => createPattern(matcher, opts));
if (testString == null) {
return (testString, ri = false) => {
const returnIndex = typeof ri === 'boolean' ? ri : false;
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
}
}
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
};
anymatch.default = anymatch;
module.exports = anymatch;

View File

@@ -1,48 +0,0 @@
{
"name": "anymatch",
"version": "3.1.3",
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions",
"files": [
"index.js",
"index.d.ts"
],
"dependencies": {
"normalize-path": "^3.0.0",
"picomatch": "^2.0.4"
},
"author": {
"name": "Elan Shanker",
"url": "https://github.com/es128"
},
"license": "ISC",
"homepage": "https://github.com/micromatch/anymatch",
"repository": {
"type": "git",
"url": "https://github.com/micromatch/anymatch"
},
"keywords": [
"match",
"any",
"string",
"file",
"fs",
"list",
"glob",
"regex",
"regexp",
"regular",
"expression",
"function"
],
"scripts": {
"test": "nyc mocha",
"mocha": "mocha"
},
"devDependencies": {
"mocha": "^6.1.3",
"nyc": "^14.0.0"
},
"engines": {
"node": ">= 8"
}
}

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,43 +0,0 @@
# Array Flatten
[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
> Flatten an array of nested arrays into a single flat array. Accepts an optional depth.
## Installation
```
npm install array-flatten --save
```
## Usage
```javascript
var flatten = require('array-flatten')
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9])
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
flatten([1, [2, [3, [4, [5], 6], 7], 8], 9], 2)
//=> [1, 2, 3, [4, [5], 6], 7, 8, 9]
(function () {
flatten(arguments) //=> [1, 2, 3]
})(1, [2, 3])
```
## License
MIT
[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat
[npm-url]: https://npmjs.org/package/array-flatten
[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat
[downloads-url]: https://npmjs.org/package/array-flatten
[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat
[travis-url]: https://travis-ci.org/blakeembrey/array-flatten
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat
[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master

View File

@@ -1,64 +0,0 @@
'use strict'
/**
* Expose `arrayFlatten`.
*/
module.exports = arrayFlatten
/**
* Recursive flatten function with depth.
*
* @param {Array} array
* @param {Array} result
* @param {Number} depth
* @return {Array}
*/
function flattenWithDepth (array, result, depth) {
for (var i = 0; i < array.length; i++) {
var value = array[i]
if (depth > 0 && Array.isArray(value)) {
flattenWithDepth(value, result, depth - 1)
} else {
result.push(value)
}
}
return result
}
/**
* Recursive flatten function. Omitting depth is slightly faster.
*
* @param {Array} array
* @param {Array} result
* @return {Array}
*/
function flattenForever (array, result) {
for (var i = 0; i < array.length; i++) {
var value = array[i]
if (Array.isArray(value)) {
flattenForever(value, result)
} else {
result.push(value)
}
}
return result
}
/**
* Flatten an array, with the ability to define a depth.
*
* @param {Array} array
* @param {Number} depth
* @return {Array}
*/
function arrayFlatten (array, depth) {
if (depth == null) {
return flattenForever(array, [])
}
return flattenWithDepth(array, [], depth)
}

View File

@@ -1,39 +0,0 @@
{
"name": "array-flatten",
"version": "1.1.1",
"description": "Flatten an array of nested arrays into a single flat array",
"main": "array-flatten.js",
"files": [
"array-flatten.js",
"LICENSE"
],
"scripts": {
"test": "istanbul cover _mocha -- -R spec"
},
"repository": {
"type": "git",
"url": "git://github.com/blakeembrey/array-flatten.git"
},
"keywords": [
"array",
"flatten",
"arguments",
"depth"
],
"author": {
"name": "Blake Embrey",
"email": "hello@blakeembrey.com",
"url": "http://blakeembrey.me"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/blakeembrey/array-flatten/issues"
},
"homepage": "https://github.com/blakeembrey/array-flatten",
"devDependencies": {
"istanbul": "^0.3.13",
"mocha": "^2.2.4",
"pre-commit": "^1.0.7",
"standard": "^3.7.3"
}
}

View File

@@ -1,2 +0,0 @@
tidelift: "npm/balanced-match"
patreon: juliangruber

View File

@@ -1,21 +0,0 @@
(MIT)
Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,97 +0,0 @@
# balanced-match
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
[![build status](https://secure.travis-ci.org/juliangruber/balanced-match.svg)](http://travis-ci.org/juliangruber/balanced-match)
[![downloads](https://img.shields.io/npm/dm/balanced-match.svg)](https://www.npmjs.org/package/balanced-match)
[![testling badge](https://ci.testling.com/juliangruber/balanced-match.png)](https://ci.testling.com/juliangruber/balanced-match)
## Example
Get the first matching pair of braces:
```js
var balanced = require('balanced-match');
console.log(balanced('{', '}', 'pre{in{nested}}post'));
console.log(balanced('{', '}', 'pre{first}between{second}post'));
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
```
The matches are:
```bash
$ node example.js
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
{ start: 3,
end: 9,
pre: 'pre',
body: 'first',
post: 'between{second}post' }
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
```
## API
### var m = balanced(a, b, str)
For the first non-nested matching pair of `a` and `b` in `str`, return an
object with those keys:
* **start** the index of the first match of `a`
* **end** the index of the matching `b`
* **pre** the preamble, `a` and `b` not included
* **body** the match, `a` and `b` not included
* **post** the postscript, `a` and `b` not included
If there's no match, `undefined` will be returned.
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
### var r = balanced.range(a, b, str)
For the first non-nested matching pair of `a` and `b` in `str`, return an
array with indexes: `[ <a index>, <b index> ]`.
If there's no match, `undefined` will be returned.
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
## Installation
With [npm](https://npmjs.org) do:
```bash
npm install balanced-match
```
## Security contact information
To report a security vulnerability, please use the
[Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.
## License
(MIT)
Copyright (c) 2013 Julian Gruber &lt;julian@juliangruber.com&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,62 +0,0 @@
'use strict';
module.exports = balanced;
function balanced(a, b, str) {
if (a instanceof RegExp) a = maybeMatch(a, str);
if (b instanceof RegExp) b = maybeMatch(b, str);
var r = range(a, b, str);
return r && {
start: r[0],
end: r[1],
pre: str.slice(0, r[0]),
body: str.slice(r[0] + a.length, r[1]),
post: str.slice(r[1] + b.length)
};
}
function maybeMatch(reg, str) {
var m = str.match(reg);
return m ? m[0] : null;
}
balanced.range = range;
function range(a, b, str) {
var begs, beg, left, right, result;
var ai = str.indexOf(a);
var bi = str.indexOf(b, ai + 1);
var i = ai;
if (ai >= 0 && bi > 0) {
if(a===b) {
return [ai, bi];
}
begs = [];
left = str.length;
while (i >= 0 && !result) {
if (i == ai) {
begs.push(i);
ai = str.indexOf(a, i + 1);
} else if (begs.length == 1) {
result = [ begs.pop(), bi ];
} else {
beg = begs.pop();
if (beg < left) {
left = beg;
right = bi;
}
bi = str.indexOf(b, i + 1);
}
i = ai < bi && ai >= 0 ? ai : bi;
}
if (begs.length) {
result = [ left, right ];
}
}
return result;
}

View File

@@ -1,48 +0,0 @@
{
"name": "balanced-match",
"description": "Match balanced character pairs, like \"{\" and \"}\"",
"version": "1.0.2",
"repository": {
"type": "git",
"url": "git://github.com/juliangruber/balanced-match.git"
},
"homepage": "https://github.com/juliangruber/balanced-match",
"main": "index.js",
"scripts": {
"test": "tape test/test.js",
"bench": "matcha test/bench.js"
},
"devDependencies": {
"matcha": "^0.7.0",
"tape": "^4.6.0"
},
"keywords": [
"match",
"regexp",
"test",
"balanced",
"parse"
],
"author": {
"name": "Julian Gruber",
"email": "mail@juliangruber.com",
"url": "http://juliangruber.com"
},
"license": "MIT",
"testling": {
"files": "test/*.js",
"browsers": [
"ie/8..latest",
"firefox/20..latest",
"firefox/nightly",
"chrome/25..latest",
"chrome/canary",
"opera/12..latest",
"opera/next",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
}
}

View File

@@ -1,52 +0,0 @@
2.0.1 / 2018-09-19
==================
* deps: safe-buffer@5.1.2
2.0.0 / 2017-09-12
==================
* Drop support for Node.js below 0.8
* Remove `auth(ctx)` signature -- pass in header or `auth(ctx.req)`
* Use `safe-buffer` for improved Buffer API
1.1.0 / 2016-11-18
==================
* Add `auth.parse` for low-level string parsing
1.0.4 / 2016-05-10
==================
* Improve error message when `req` argument is not an object
* Improve error message when `req` missing `headers` property
1.0.3 / 2015-07-01
==================
* Fix regression accepting a Koa context
1.0.2 / 2015-06-12
==================
* Improve error message when `req` argument missing
* perf: enable strict mode
* perf: hoist regular expression
* perf: parse with regular expressions
* perf: remove argument reassignment
1.0.1 / 2015-05-04
==================
* Update readme
1.0.0 / 2014-07-01
==================
* Support empty password
* Support empty username
0.0.1 / 2013-11-30
==================
* Initial release

View File

@@ -1,24 +0,0 @@
(The MIT License)
Copyright (c) 2013 TJ Holowaychuk
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2015-2016 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,113 +0,0 @@
# basic-auth
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Node.js Version][node-version-image]][node-version-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
Generic basic auth Authorization header field parser for whatever.
## Installation
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```
$ npm install basic-auth
```
## API
<!-- eslint-disable no-unused-vars -->
```js
var auth = require('basic-auth')
```
### auth(req)
Get the basic auth credentials from the given request. The `Authorization`
header is parsed and if the header is invalid, `undefined` is returned,
otherwise an object with `name` and `pass` properties.
### auth.parse(string)
Parse a basic auth authorization header string. This will return an object
with `name` and `pass` properties, or `undefined` if the string is invalid.
## Example
Pass a Node.js request object to the module export. If parsing fails
`undefined` is returned, otherwise an object with `.name` and `.pass`.
<!-- eslint-disable no-unused-vars, no-undef -->
```js
var auth = require('basic-auth')
var user = auth(req)
// => { name: 'something', pass: 'whatever' }
```
A header string from any other location can also be parsed with
`auth.parse`, for example a `Proxy-Authorization` header:
<!-- eslint-disable no-unused-vars, no-undef -->
```js
var auth = require('basic-auth')
var user = auth.parse(req.getHeader('Proxy-Authorization'))
```
### With vanilla node.js http server
```js
var http = require('http')
var auth = require('basic-auth')
var compare = require('tsscmp')
// Create server
var server = http.createServer(function (req, res) {
var credentials = auth(req)
// Check credentials
// The "check" function will typically be against your user store
if (!credentials || !check(credentials.name, credentials.pass)) {
res.statusCode = 401
res.setHeader('WWW-Authenticate', 'Basic realm="example"')
res.end('Access denied')
} else {
res.end('Access granted')
}
})
// Basic function to validate credentials for example
function check (name, pass) {
var valid = true
// Simple method to prevent short-circut and use timing-safe compare
valid = compare(name, 'john') && valid
valid = compare(pass, 'secret') && valid
return valid
}
// Listen
server.listen(3000)
```
# License
[MIT](LICENSE)
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/basic-auth/master
[coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master
[downloads-image]: https://badgen.net/npm/dm/basic-auth
[downloads-url]: https://npmjs.org/package/basic-auth
[node-version-image]: https://badgen.net/npm/node/basic-auth
[node-version-url]: https://nodejs.org/en/download
[npm-image]: https://badgen.net/npm/v/basic-auth
[npm-url]: https://npmjs.org/package/basic-auth
[travis-image]: https://badgen.net/travis/jshttp/basic-auth/master
[travis-url]: https://travis-ci.org/jshttp/basic-auth

View File

@@ -1,133 +0,0 @@
/*!
* basic-auth
* Copyright(c) 2013 TJ Holowaychuk
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015-2016 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var Buffer = require('safe-buffer').Buffer
/**
* Module exports.
* @public
*/
module.exports = auth
module.exports.parse = parse
/**
* RegExp for basic auth credentials
*
* credentials = auth-scheme 1*SP token68
* auth-scheme = "Basic" ; case insensitive
* token68 = 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="
* @private
*/
var CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/
/**
* RegExp for basic auth user/pass
*
* user-pass = userid ":" password
* userid = *<TEXT excluding ":">
* password = *TEXT
* @private
*/
var USER_PASS_REGEXP = /^([^:]*):(.*)$/
/**
* Parse the Authorization header field of a request.
*
* @param {object} req
* @return {object} with .name and .pass
* @public
*/
function auth (req) {
if (!req) {
throw new TypeError('argument req is required')
}
if (typeof req !== 'object') {
throw new TypeError('argument req is required to be an object')
}
// get header
var header = getAuthorization(req)
// parse header
return parse(header)
}
/**
* Decode base64 string.
* @private
*/
function decodeBase64 (str) {
return Buffer.from(str, 'base64').toString()
}
/**
* Get the Authorization header from request object.
* @private
*/
function getAuthorization (req) {
if (!req.headers || typeof req.headers !== 'object') {
throw new TypeError('argument req is required to have headers property')
}
return req.headers.authorization
}
/**
* Parse basic auth to object.
*
* @param {string} string
* @return {object}
* @public
*/
function parse (string) {
if (typeof string !== 'string') {
return undefined
}
// parse header
var match = CREDENTIALS_REGEXP.exec(string)
if (!match) {
return undefined
}
// decode user pass
var userPass = USER_PASS_REGEXP.exec(decodeBase64(match[1]))
if (!userPass) {
return undefined
}
// return credentials object
return new Credentials(userPass[1], userPass[2])
}
/**
* Object to represent user credentials.
* @private
*/
function Credentials (name, pass) {
this.name = name
this.pass = pass
}

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) Feross Aboukhadijeh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,584 +0,0 @@
# safe-buffer [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
[travis-image]: https://img.shields.io/travis/feross/safe-buffer/master.svg
[travis-url]: https://travis-ci.org/feross/safe-buffer
[npm-image]: https://img.shields.io/npm/v/safe-buffer.svg
[npm-url]: https://npmjs.org/package/safe-buffer
[downloads-image]: https://img.shields.io/npm/dm/safe-buffer.svg
[downloads-url]: https://npmjs.org/package/safe-buffer
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com
#### Safer Node.js Buffer API
**Use the new Node.js Buffer APIs (`Buffer.from`, `Buffer.alloc`,
`Buffer.allocUnsafe`, `Buffer.allocUnsafeSlow`) in all versions of Node.js.**
**Uses the built-in implementation when available.**
## install
```
npm install safe-buffer
```
## usage
The goal of this package is to provide a safe replacement for the node.js `Buffer`.
It's a drop-in replacement for `Buffer`. You can use it by adding one `require` line to
the top of your node.js modules:
```js
var Buffer = require('safe-buffer').Buffer
// Existing buffer code will continue to work without issues:
new Buffer('hey', 'utf8')
new Buffer([1, 2, 3], 'utf8')
new Buffer(obj)
new Buffer(16) // create an uninitialized buffer (potentially unsafe)
// But you can use these new explicit APIs to make clear what you want:
Buffer.from('hey', 'utf8') // convert from many types to a Buffer
Buffer.alloc(16) // create a zero-filled buffer (safe)
Buffer.allocUnsafe(16) // create an uninitialized buffer (potentially unsafe)
```
## api
### Class Method: Buffer.from(array)
<!-- YAML
added: v3.0.0
-->
* `array` {Array}
Allocates a new `Buffer` using an `array` of octets.
```js
const buf = Buffer.from([0x62,0x75,0x66,0x66,0x65,0x72]);
// creates a new Buffer containing ASCII bytes
// ['b','u','f','f','e','r']
```
A `TypeError` will be thrown if `array` is not an `Array`.
### Class Method: Buffer.from(arrayBuffer[, byteOffset[, length]])
<!-- YAML
added: v5.10.0
-->
* `arrayBuffer` {ArrayBuffer} The `.buffer` property of a `TypedArray` or
a `new ArrayBuffer()`
* `byteOffset` {Number} Default: `0`
* `length` {Number} Default: `arrayBuffer.length - byteOffset`
When passed a reference to the `.buffer` property of a `TypedArray` instance,
the newly created `Buffer` will share the same allocated memory as the
TypedArray.
```js
const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;
const buf = Buffer.from(arr.buffer); // shares the memory with arr;
console.log(buf);
// Prints: <Buffer 88 13 a0 0f>
// changing the TypedArray changes the Buffer also
arr[1] = 6000;
console.log(buf);
// Prints: <Buffer 88 13 70 17>
```
The optional `byteOffset` and `length` arguments specify a memory range within
the `arrayBuffer` that will be shared by the `Buffer`.
```js
const ab = new ArrayBuffer(10);
const buf = Buffer.from(ab, 0, 2);
console.log(buf.length);
// Prints: 2
```
A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer`.
### Class Method: Buffer.from(buffer)
<!-- YAML
added: v3.0.0
-->
* `buffer` {Buffer}
Copies the passed `buffer` data onto a new `Buffer` instance.
```js
const buf1 = Buffer.from('buffer');
const buf2 = Buffer.from(buf1);
buf1[0] = 0x61;
console.log(buf1.toString());
// 'auffer'
console.log(buf2.toString());
// 'buffer' (copy is not changed)
```
A `TypeError` will be thrown if `buffer` is not a `Buffer`.
### Class Method: Buffer.from(str[, encoding])
<!-- YAML
added: v5.10.0
-->
* `str` {String} String to encode.
* `encoding` {String} Encoding to use, Default: `'utf8'`
Creates a new `Buffer` containing the given JavaScript string `str`. If
provided, the `encoding` parameter identifies the character encoding.
If not provided, `encoding` defaults to `'utf8'`.
```js
const buf1 = Buffer.from('this is a tést');
console.log(buf1.toString());
// prints: this is a tést
console.log(buf1.toString('ascii'));
// prints: this is a tC)st
const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
console.log(buf2.toString());
// prints: this is a tést
```
A `TypeError` will be thrown if `str` is not a string.
### Class Method: Buffer.alloc(size[, fill[, encoding]])
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
* `fill` {Value} Default: `undefined`
* `encoding` {String} Default: `utf8`
Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the
`Buffer` will be *zero-filled*.
```js
const buf = Buffer.alloc(5);
console.log(buf);
// <Buffer 00 00 00 00 00>
```
The `size` must be less than or equal to the value of
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
be created if a `size` less than or equal to 0 is specified.
If `fill` is specified, the allocated `Buffer` will be initialized by calling
`buf.fill(fill)`. See [`buf.fill()`][] for more information.
```js
const buf = Buffer.alloc(5, 'a');
console.log(buf);
// <Buffer 61 61 61 61 61>
```
If both `fill` and `encoding` are specified, the allocated `Buffer` will be
initialized by calling `buf.fill(fill, encoding)`. For example:
```js
const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
console.log(buf);
// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
```
Calling `Buffer.alloc(size)` can be significantly slower than the alternative
`Buffer.allocUnsafe(size)` but ensures that the newly created `Buffer` instance
contents will *never contain sensitive data*.
A `TypeError` will be thrown if `size` is not a number.
### Class Method: Buffer.allocUnsafe(size)
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must
be less than or equal to the value of `require('buffer').kMaxLength` (on 64-bit
architectures, `kMaxLength` is `(2^31)-1`). Otherwise, a [`RangeError`][] is
thrown. A zero-length Buffer will be created if a `size` less than or equal to
0 is specified.
The underlying memory for `Buffer` instances created in this way is *not
initialized*. The contents of the newly created `Buffer` are unknown and
*may contain sensitive data*. Use [`buf.fill(0)`][] to initialize such
`Buffer` instances to zeroes.
```js
const buf = Buffer.allocUnsafe(5);
console.log(buf);
// <Buffer 78 e0 82 02 01>
// (octets will be different, every time)
buf.fill(0);
console.log(buf);
// <Buffer 00 00 00 00 00>
```
A `TypeError` will be thrown if `size` is not a number.
Note that the `Buffer` module pre-allocates an internal `Buffer` instance of
size `Buffer.poolSize` that is used as a pool for the fast allocation of new
`Buffer` instances created using `Buffer.allocUnsafe(size)` (and the deprecated
`new Buffer(size)` constructor) only when `size` is less than or equal to
`Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two). The default
value of `Buffer.poolSize` is `8192` but can be modified.
Use of this pre-allocated internal memory pool is a key difference between
calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
Specifically, `Buffer.alloc(size, fill)` will *never* use the internal Buffer
pool, while `Buffer.allocUnsafe(size).fill(fill)` *will* use the internal
Buffer pool if `size` is less than or equal to half `Buffer.poolSize`. The
difference is subtle but can be important when an application requires the
additional performance that `Buffer.allocUnsafe(size)` provides.
### Class Method: Buffer.allocUnsafeSlow(size)
<!-- YAML
added: v5.10.0
-->
* `size` {Number}
Allocates a new *non-zero-filled* and non-pooled `Buffer` of `size` bytes. The
`size` must be less than or equal to the value of
`require('buffer').kMaxLength` (on 64-bit architectures, `kMaxLength` is
`(2^31)-1`). Otherwise, a [`RangeError`][] is thrown. A zero-length Buffer will
be created if a `size` less than or equal to 0 is specified.
The underlying memory for `Buffer` instances created in this way is *not
initialized*. The contents of the newly created `Buffer` are unknown and
*may contain sensitive data*. Use [`buf.fill(0)`][] to initialize such
`Buffer` instances to zeroes.
When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
allocations under 4KB are, by default, sliced from a single pre-allocated
`Buffer`. This allows applications to avoid the garbage collection overhead of
creating many individually allocated Buffers. This approach improves both
performance and memory usage by eliminating the need to track and cleanup as
many `Persistent` objects.
However, in the case where a developer may need to retain a small chunk of
memory from a pool for an indeterminate amount of time, it may be appropriate
to create an un-pooled Buffer instance using `Buffer.allocUnsafeSlow()` then
copy out the relevant bits.
```js
// need to keep around a few small chunks of memory
const store = [];
socket.on('readable', () => {
const data = socket.read();
// allocate for retained data
const sb = Buffer.allocUnsafeSlow(10);
// copy the data into the new allocation
data.copy(sb, 0, 0, 10);
store.push(sb);
});
```
Use of `Buffer.allocUnsafeSlow()` should be used only as a last resort *after*
a developer has observed undue memory retention in their applications.
A `TypeError` will be thrown if `size` is not a number.
### All the Rest
The rest of the `Buffer` API is exactly the same as in node.js.
[See the docs](https://nodejs.org/api/buffer.html).
## Related links
- [Node.js issue: Buffer(number) is unsafe](https://github.com/nodejs/node/issues/4660)
- [Node.js Enhancement Proposal: Buffer.from/Buffer.alloc/Buffer.zalloc/Buffer() soft-deprecate](https://github.com/nodejs/node-eps/pull/4)
## Why is `Buffer` unsafe?
Today, the node.js `Buffer` constructor is overloaded to handle many different argument
types like `String`, `Array`, `Object`, `TypedArrayView` (`Uint8Array`, etc.),
`ArrayBuffer`, and also `Number`.
The API is optimized for convenience: you can throw any type at it, and it will try to do
what you want.
Because the Buffer constructor is so powerful, you often see code like this:
```js
// Convert UTF-8 strings to hex
function toHex (str) {
return new Buffer(str).toString('hex')
}
```
***But what happens if `toHex` is called with a `Number` argument?***
### Remote Memory Disclosure
If an attacker can make your program call the `Buffer` constructor with a `Number`
argument, then they can make it allocate uninitialized memory from the node.js process.
This could potentially disclose TLS private keys, user data, or database passwords.
When the `Buffer` constructor is passed a `Number` argument, it returns an
**UNINITIALIZED** block of memory of the specified `size`. When you create a `Buffer` like
this, you **MUST** overwrite the contents before returning it to the user.
From the [node.js docs](https://nodejs.org/api/buffer.html#buffer_new_buffer_size):
> `new Buffer(size)`
>
> - `size` Number
>
> The underlying memory for `Buffer` instances created in this way is not initialized.
> **The contents of a newly created `Buffer` are unknown and could contain sensitive
> data.** Use `buf.fill(0)` to initialize a Buffer to zeroes.
(Emphasis our own.)
Whenever the programmer intended to create an uninitialized `Buffer` you often see code
like this:
```js
var buf = new Buffer(16)
// Immediately overwrite the uninitialized buffer with data from another buffer
for (var i = 0; i < buf.length; i++) {
buf[i] = otherBuf[i]
}
```
### Would this ever be a problem in real code?
Yes. It's surprisingly common to forget to check the type of your variables in a
dynamically-typed language like JavaScript.
Usually the consequences of assuming the wrong type is that your program crashes with an
uncaught exception. But the failure mode for forgetting to check the type of arguments to
the `Buffer` constructor is more catastrophic.
Here's an example of a vulnerable service that takes a JSON payload and converts it to
hex:
```js
// Take a JSON payload {str: "some string"} and convert it to hex
var server = http.createServer(function (req, res) {
var data = ''
req.setEncoding('utf8')
req.on('data', function (chunk) {
data += chunk
})
req.on('end', function () {
var body = JSON.parse(data)
res.end(new Buffer(body.str).toString('hex'))
})
})
server.listen(8080)
```
In this example, an http client just has to send:
```json
{
"str": 1000
}
```
and it will get back 1,000 bytes of uninitialized memory from the server.
This is a very serious bug. It's similar in severity to the
[the Heartbleed bug](http://heartbleed.com/) that allowed disclosure of OpenSSL process
memory by remote attackers.
### Which real-world packages were vulnerable?
#### [`bittorrent-dht`](https://www.npmjs.com/package/bittorrent-dht)
[Mathias Buus](https://github.com/mafintosh) and I
([Feross Aboukhadijeh](http://feross.org/)) found this issue in one of our own packages,
[`bittorrent-dht`](https://www.npmjs.com/package/bittorrent-dht). The bug would allow
anyone on the internet to send a series of messages to a user of `bittorrent-dht` and get
them to reveal 20 bytes at a time of uninitialized memory from the node.js process.
Here's
[the commit](https://github.com/feross/bittorrent-dht/commit/6c7da04025d5633699800a99ec3fbadf70ad35b8)
that fixed it. We released a new fixed version, created a
[Node Security Project disclosure](https://nodesecurity.io/advisories/68), and deprecated all
vulnerable versions on npm so users will get a warning to upgrade to a newer version.
#### [`ws`](https://www.npmjs.com/package/ws)
That got us wondering if there were other vulnerable packages. Sure enough, within a short
period of time, we found the same issue in [`ws`](https://www.npmjs.com/package/ws), the
most popular WebSocket implementation in node.js.
If certain APIs were called with `Number` parameters instead of `String` or `Buffer` as
expected, then uninitialized server memory would be disclosed to the remote peer.
These were the vulnerable methods:
```js
socket.send(number)
socket.ping(number)
socket.pong(number)
```
Here's a vulnerable socket server with some echo functionality:
```js
server.on('connection', function (socket) {
socket.on('message', function (message) {
message = JSON.parse(message)
if (message.type === 'echo') {
socket.send(message.data) // send back the user's message
}
})
})
```
`socket.send(number)` called on the server, will disclose server memory.
Here's [the release](https://github.com/websockets/ws/releases/tag/1.0.1) where the issue
was fixed, with a more detailed explanation. Props to
[Arnout Kazemier](https://github.com/3rd-Eden) for the quick fix. Here's the
[Node Security Project disclosure](https://nodesecurity.io/advisories/67).
### What's the solution?
It's important that node.js offers a fast way to get memory otherwise performance-critical
applications would needlessly get a lot slower.
But we need a better way to *signal our intent* as programmers. **When we want
uninitialized memory, we should request it explicitly.**
Sensitive functionality should not be packed into a developer-friendly API that loosely
accepts many different types. This type of API encourages the lazy practice of passing
variables in without checking the type very carefully.
#### A new API: `Buffer.allocUnsafe(number)`
The functionality of creating buffers with uninitialized memory should be part of another
API. We propose `Buffer.allocUnsafe(number)`. This way, it's not part of an API that
frequently gets user input of all sorts of different types passed into it.
```js
var buf = Buffer.allocUnsafe(16) // careful, uninitialized memory!
// Immediately overwrite the uninitialized buffer with data from another buffer
for (var i = 0; i < buf.length; i++) {
buf[i] = otherBuf[i]
}
```
### How do we fix node.js core?
We sent [a PR to node.js core](https://github.com/nodejs/node/pull/4514) (merged as
`semver-major`) which defends against one case:
```js
var str = 16
new Buffer(str, 'utf8')
```
In this situation, it's implied that the programmer intended the first argument to be a
string, since they passed an encoding as a second argument. Today, node.js will allocate
uninitialized memory in the case of `new Buffer(number, encoding)`, which is probably not
what the programmer intended.
But this is only a partial solution, since if the programmer does `new Buffer(variable)`
(without an `encoding` parameter) there's no way to know what they intended. If `variable`
is sometimes a number, then uninitialized memory will sometimes be returned.
### What's the real long-term fix?
We could deprecate and remove `new Buffer(number)` and use `Buffer.allocUnsafe(number)` when
we need uninitialized memory. But that would break 1000s of packages.
~~We believe the best solution is to:~~
~~1. Change `new Buffer(number)` to return safe, zeroed-out memory~~
~~2. Create a new API for creating uninitialized Buffers. We propose: `Buffer.allocUnsafe(number)`~~
#### Update
We now support adding three new APIs:
- `Buffer.from(value)` - convert from any type to a buffer
- `Buffer.alloc(size)` - create a zero-filled buffer
- `Buffer.allocUnsafe(size)` - create an uninitialized buffer with given size
This solves the core problem that affected `ws` and `bittorrent-dht` which is
`Buffer(variable)` getting tricked into taking a number argument.
This way, existing code continues working and the impact on the npm ecosystem will be
minimal. Over time, npm maintainers can migrate performance-critical code to use
`Buffer.allocUnsafe(number)` instead of `new Buffer(number)`.
### Conclusion
We think there's a serious design issue with the `Buffer` API as it exists today. It
promotes insecure software by putting high-risk functionality into a convenient API
with friendly "developer ergonomics".
This wasn't merely a theoretical exercise because we found the issue in some of the
most popular npm packages.
Fortunately, there's an easy fix that can be applied today. Use `safe-buffer` in place of
`buffer`.
```js
var Buffer = require('safe-buffer').Buffer
```
Eventually, we hope that node.js core can switch to this new, safer behavior. We believe
the impact on the ecosystem would be minimal since it's not a breaking change.
Well-maintained, popular packages would be updated to use `Buffer.alloc` quickly, while
older, insecure packages would magically become safe from this attack vector.
## links
- [Node.js PR: buffer: throw if both length and enc are passed](https://github.com/nodejs/node/pull/4514)
- [Node Security Project disclosure for `ws`](https://nodesecurity.io/advisories/67)
- [Node Security Project disclosure for`bittorrent-dht`](https://nodesecurity.io/advisories/68)
## credit
The original issues in `bittorrent-dht`
([disclosure](https://nodesecurity.io/advisories/68)) and
`ws` ([disclosure](https://nodesecurity.io/advisories/67)) were discovered by
[Mathias Buus](https://github.com/mafintosh) and
[Feross Aboukhadijeh](http://feross.org/).
Thanks to [Adam Baldwin](https://github.com/evilpacket) for helping disclose these issues
and for his work running the [Node Security Project](https://nodesecurity.io/).
Thanks to [John Hiesey](https://github.com/jhiesey) for proofreading this README and
auditing the code.
## license
MIT. Copyright (C) [Feross Aboukhadijeh](http://feross.org)

View File

@@ -1,187 +0,0 @@
declare module "safe-buffer" {
export class Buffer {
length: number
write(string: string, offset?: number, length?: number, encoding?: string): number;
toString(encoding?: string, start?: number, end?: number): string;
toJSON(): { type: 'Buffer', data: any[] };
equals(otherBuffer: Buffer): boolean;
compare(otherBuffer: Buffer, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number;
copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
slice(start?: number, end?: number): Buffer;
writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
readIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
readIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
readUInt8(offset: number, noAssert?: boolean): number;
readUInt16LE(offset: number, noAssert?: boolean): number;
readUInt16BE(offset: number, noAssert?: boolean): number;
readUInt32LE(offset: number, noAssert?: boolean): number;
readUInt32BE(offset: number, noAssert?: boolean): number;
readInt8(offset: number, noAssert?: boolean): number;
readInt16LE(offset: number, noAssert?: boolean): number;
readInt16BE(offset: number, noAssert?: boolean): number;
readInt32LE(offset: number, noAssert?: boolean): number;
readInt32BE(offset: number, noAssert?: boolean): number;
readFloatLE(offset: number, noAssert?: boolean): number;
readFloatBE(offset: number, noAssert?: boolean): number;
readDoubleLE(offset: number, noAssert?: boolean): number;
readDoubleBE(offset: number, noAssert?: boolean): number;
swap16(): Buffer;
swap32(): Buffer;
swap64(): Buffer;
writeUInt8(value: number, offset: number, noAssert?: boolean): number;
writeUInt16LE(value: number, offset: number, noAssert?: boolean): number;
writeUInt16BE(value: number, offset: number, noAssert?: boolean): number;
writeUInt32LE(value: number, offset: number, noAssert?: boolean): number;
writeUInt32BE(value: number, offset: number, noAssert?: boolean): number;
writeInt8(value: number, offset: number, noAssert?: boolean): number;
writeInt16LE(value: number, offset: number, noAssert?: boolean): number;
writeInt16BE(value: number, offset: number, noAssert?: boolean): number;
writeInt32LE(value: number, offset: number, noAssert?: boolean): number;
writeInt32BE(value: number, offset: number, noAssert?: boolean): number;
writeFloatLE(value: number, offset: number, noAssert?: boolean): number;
writeFloatBE(value: number, offset: number, noAssert?: boolean): number;
writeDoubleLE(value: number, offset: number, noAssert?: boolean): number;
writeDoubleBE(value: number, offset: number, noAssert?: boolean): number;
fill(value: any, offset?: number, end?: number): this;
indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number;
includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean;
/**
* Allocates a new buffer containing the given {str}.
*
* @param str String to store in buffer.
* @param encoding encoding to use, optional. Default is 'utf8'
*/
constructor (str: string, encoding?: string);
/**
* Allocates a new buffer of {size} octets.
*
* @param size count of octets to allocate.
*/
constructor (size: number);
/**
* Allocates a new buffer containing the given {array} of octets.
*
* @param array The octets to store.
*/
constructor (array: Uint8Array);
/**
* Produces a Buffer backed by the same allocated memory as
* the given {ArrayBuffer}.
*
*
* @param arrayBuffer The ArrayBuffer with which to share memory.
*/
constructor (arrayBuffer: ArrayBuffer);
/**
* Allocates a new buffer containing the given {array} of octets.
*
* @param array The octets to store.
*/
constructor (array: any[]);
/**
* Copies the passed {buffer} data onto a new {Buffer} instance.
*
* @param buffer The buffer to copy.
*/
constructor (buffer: Buffer);
prototype: Buffer;
/**
* Allocates a new Buffer using an {array} of octets.
*
* @param array
*/
static from(array: any[]): Buffer;
/**
* When passed a reference to the .buffer property of a TypedArray instance,
* the newly created Buffer will share the same allocated memory as the TypedArray.
* The optional {byteOffset} and {length} arguments specify a memory range
* within the {arrayBuffer} that will be shared by the Buffer.
*
* @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer()
* @param byteOffset
* @param length
*/
static from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
/**
* Copies the passed {buffer} data onto a new Buffer instance.
*
* @param buffer
*/
static from(buffer: Buffer): Buffer;
/**
* Creates a new Buffer containing the given JavaScript string {str}.
* If provided, the {encoding} parameter identifies the character encoding.
* If not provided, {encoding} defaults to 'utf8'.
*
* @param str
*/
static from(str: string, encoding?: string): Buffer;
/**
* Returns true if {obj} is a Buffer
*
* @param obj object to test.
*/
static isBuffer(obj: any): obj is Buffer;
/**
* Returns true if {encoding} is a valid encoding argument.
* Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
*
* @param encoding string to test.
*/
static isEncoding(encoding: string): boolean;
/**
* Gives the actual byte length of a string. encoding defaults to 'utf8'.
* This is not the same as String.prototype.length since that returns the number of characters in a string.
*
* @param string string to test.
* @param encoding encoding used to evaluate (defaults to 'utf8')
*/
static byteLength(string: string, encoding?: string): number;
/**
* Returns a buffer which is the result of concatenating all the buffers in the list together.
*
* If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer.
* If the list has exactly one item, then the first item of the list is returned.
* If the list has more than one item, then a new Buffer is created.
*
* @param list An array of Buffer objects to concatenate
* @param totalLength Total length of the buffers when concatenated.
* If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.
*/
static concat(list: Buffer[], totalLength?: number): Buffer;
/**
* The same as buf1.compare(buf2).
*/
static compare(buf1: Buffer, buf2: Buffer): number;
/**
* Allocates a new buffer of {size} octets.
*
* @param size count of octets to allocate.
* @param fill if specified, buffer will be initialized by calling buf.fill(fill).
* If parameter is omitted, buffer will be filled with zeros.
* @param encoding encoding used for call to buf.fill while initalizing
*/
static alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer;
/**
* Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents
* of the newly created Buffer are unknown and may contain sensitive data.
*
* @param size count of octets to allocate
*/
static allocUnsafe(size: number): Buffer;
/**
* Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents
* of the newly created Buffer are unknown and may contain sensitive data.
*
* @param size count of octets to allocate
*/
static allocUnsafeSlow(size: number): Buffer;
}
}

View File

@@ -1,62 +0,0 @@
/* eslint-disable node/no-deprecated-api */
var buffer = require('buffer')
var Buffer = buffer.Buffer
// alternative to using Object.keys for old browsers
function copyProps (src, dst) {
for (var key in src) {
dst[key] = src[key]
}
}
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
module.exports = buffer
} else {
// Copy properties from require('buffer')
copyProps(buffer, exports)
exports.Buffer = SafeBuffer
}
function SafeBuffer (arg, encodingOrOffset, length) {
return Buffer(arg, encodingOrOffset, length)
}
// Copy static methods from Buffer
copyProps(Buffer, SafeBuffer)
SafeBuffer.from = function (arg, encodingOrOffset, length) {
if (typeof arg === 'number') {
throw new TypeError('Argument must not be a number')
}
return Buffer(arg, encodingOrOffset, length)
}
SafeBuffer.alloc = function (size, fill, encoding) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
var buf = Buffer(size)
if (fill !== undefined) {
if (typeof encoding === 'string') {
buf.fill(fill, encoding)
} else {
buf.fill(fill)
}
} else {
buf.fill(0)
}
return buf
}
SafeBuffer.allocUnsafe = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return Buffer(size)
}
SafeBuffer.allocUnsafeSlow = function (size) {
if (typeof size !== 'number') {
throw new TypeError('Argument must be a number')
}
return buffer.SlowBuffer(size)
}

View File

@@ -1,37 +0,0 @@
{
"name": "safe-buffer",
"description": "Safer Node.js Buffer API",
"version": "5.1.2",
"author": {
"name": "Feross Aboukhadijeh",
"email": "feross@feross.org",
"url": "http://feross.org"
},
"bugs": {
"url": "https://github.com/feross/safe-buffer/issues"
},
"devDependencies": {
"standard": "*",
"tape": "^4.0.0"
},
"homepage": "https://github.com/feross/safe-buffer",
"keywords": [
"buffer",
"buffer allocate",
"node security",
"safe",
"safe-buffer",
"security",
"uninitialized"
],
"license": "MIT",
"main": "index.js",
"types": "index.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/feross/safe-buffer.git"
},
"scripts": {
"test": "standard && tape test/*.js"
}
}

View File

@@ -1,41 +0,0 @@
{
"name": "basic-auth",
"description": "node.js basic auth parser",
"version": "2.0.1",
"license": "MIT",
"keywords": [
"basic",
"auth",
"authorization",
"basicauth"
],
"repository": "jshttp/basic-auth",
"dependencies": {
"safe-buffer": "5.1.2"
},
"devDependencies": {
"eslint": "5.6.0",
"eslint-config-standard": "12.0.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-markdown": "1.0.0-beta.6",
"eslint-plugin-node": "7.0.1",
"eslint-plugin-promise": "4.0.1",
"eslint-plugin-standard": "4.0.0",
"istanbul": "0.4.5",
"mocha": "5.2.0"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js"
],
"engines": {
"node": ">= 0.8"
},
"scripts": {
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --check-leaks --reporter spec --bail",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
}
}

View File

@@ -1,263 +0,0 @@
[
"3dm",
"3ds",
"3g2",
"3gp",
"7z",
"a",
"aac",
"adp",
"afdesign",
"afphoto",
"afpub",
"ai",
"aif",
"aiff",
"alz",
"ape",
"apk",
"appimage",
"ar",
"arj",
"asf",
"au",
"avi",
"bak",
"baml",
"bh",
"bin",
"bk",
"bmp",
"btif",
"bz2",
"bzip2",
"cab",
"caf",
"cgm",
"class",
"cmx",
"cpio",
"cr2",
"cur",
"dat",
"dcm",
"deb",
"dex",
"djvu",
"dll",
"dmg",
"dng",
"doc",
"docm",
"docx",
"dot",
"dotm",
"dra",
"DS_Store",
"dsk",
"dts",
"dtshd",
"dvb",
"dwg",
"dxf",
"ecelp4800",
"ecelp7470",
"ecelp9600",
"egg",
"eol",
"eot",
"epub",
"exe",
"f4v",
"fbs",
"fh",
"fla",
"flac",
"flatpak",
"fli",
"flv",
"fpx",
"fst",
"fvt",
"g3",
"gh",
"gif",
"graffle",
"gz",
"gzip",
"h261",
"h263",
"h264",
"icns",
"ico",
"ief",
"img",
"ipa",
"iso",
"jar",
"jpeg",
"jpg",
"jpgv",
"jpm",
"jxr",
"key",
"ktx",
"lha",
"lib",
"lvp",
"lz",
"lzh",
"lzma",
"lzo",
"m3u",
"m4a",
"m4v",
"mar",
"mdi",
"mht",
"mid",
"midi",
"mj2",
"mka",
"mkv",
"mmr",
"mng",
"mobi",
"mov",
"movie",
"mp3",
"mp4",
"mp4a",
"mpeg",
"mpg",
"mpga",
"mxu",
"nef",
"npx",
"numbers",
"nupkg",
"o",
"odp",
"ods",
"odt",
"oga",
"ogg",
"ogv",
"otf",
"ott",
"pages",
"pbm",
"pcx",
"pdb",
"pdf",
"pea",
"pgm",
"pic",
"png",
"pnm",
"pot",
"potm",
"potx",
"ppa",
"ppam",
"ppm",
"pps",
"ppsm",
"ppsx",
"ppt",
"pptm",
"pptx",
"psd",
"pya",
"pyc",
"pyo",
"pyv",
"qt",
"rar",
"ras",
"raw",
"resources",
"rgb",
"rip",
"rlc",
"rmf",
"rmvb",
"rpm",
"rtf",
"rz",
"s3m",
"s7z",
"scpt",
"sgi",
"shar",
"snap",
"sil",
"sketch",
"slk",
"smv",
"snk",
"so",
"stl",
"suo",
"sub",
"swf",
"tar",
"tbz",
"tbz2",
"tga",
"tgz",
"thmx",
"tif",
"tiff",
"tlz",
"ttc",
"ttf",
"txz",
"udf",
"uvh",
"uvi",
"uvm",
"uvp",
"uvs",
"uvu",
"viv",
"vob",
"war",
"wav",
"wax",
"wbmp",
"wdp",
"weba",
"webm",
"webp",
"whl",
"wim",
"wm",
"wma",
"wmv",
"wmx",
"woff",
"woff2",
"wrm",
"wvx",
"xbm",
"xif",
"xla",
"xlam",
"xls",
"xlsb",
"xlsm",
"xlsx",
"xlt",
"xltm",
"xltx",
"xm",
"xmind",
"xpi",
"xpm",
"xwd",
"xz",
"z",
"zip",
"zipx"
]

View File

@@ -1,3 +0,0 @@
declare const binaryExtensionsJson: readonly string[];
export = binaryExtensionsJson;

View File

@@ -1,14 +0,0 @@
/**
List of binary file extensions.
@example
```
import binaryExtensions = require('binary-extensions');
console.log(binaryExtensions);
//=> ['3ds', '3g2', …]
```
*/
declare const binaryExtensions: readonly string[];
export = binaryExtensions;

View File

@@ -1 +0,0 @@
module.exports = require('./binary-extensions.json');

View File

@@ -1,10 +0,0 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Copyright (c) Paul Miller (https://paulmillr.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,40 +0,0 @@
{
"name": "binary-extensions",
"version": "2.3.0",
"description": "List of binary file extensions",
"license": "MIT",
"repository": "sindresorhus/binary-extensions",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"sideEffects": false,
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts",
"binary-extensions.json",
"binary-extensions.json.d.ts"
],
"keywords": [
"binary",
"extensions",
"extension",
"file",
"json",
"list",
"array"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

View File

@@ -1,25 +0,0 @@
# binary-extensions
> List of binary file extensions
The list is just a [JSON file](binary-extensions.json) and can be used anywhere.
## Install
```sh
npm install binary-extensions
```
## Usage
```js
const binaryExtensions = require('binary-extensions');
console.log(binaryExtensions);
//=> ['3ds', '3g2', …]
```
## Related
- [is-binary-path](https://github.com/sindresorhus/is-binary-path) - Check if a filepath is a binary file
- [text-extensions](https://github.com/sindresorhus/text-extensions) - List of text file extensions

View File

@@ -1,672 +0,0 @@
1.20.3 / 2024-09-10
===================
* deps: qs@6.13.0
* add `depth` option to customize the depth level in the parser
* IMPORTANT: The default `depth` level for parsing URL-encoded data is now `32` (previously was `Infinity`)
1.20.2 / 2023-02-21
===================
* Fix strict json error message on Node.js 19+
* deps: content-type@~1.0.5
- perf: skip value escaping when unnecessary
* deps: raw-body@2.5.2
1.20.1 / 2022-10-06
===================
* deps: qs@6.11.0
* perf: remove unnecessary object clone
1.20.0 / 2022-04-02
===================
* Fix error message for json parse whitespace in `strict`
* Fix internal error when inflated body exceeds limit
* Prevent loss of async hooks context
* Prevent hanging when request already read
* deps: depd@2.0.0
- Replace internal `eval` usage with `Function` constructor
- Use instance methods on `process` to check for listeners
* deps: http-errors@2.0.0
- deps: depd@2.0.0
- deps: statuses@2.0.1
* deps: on-finished@2.4.1
* deps: qs@6.10.3
* deps: raw-body@2.5.1
- deps: http-errors@2.0.0
1.19.2 / 2022-02-15
===================
* deps: bytes@3.1.2
* deps: qs@6.9.7
* Fix handling of `__proto__` keys
* deps: raw-body@2.4.3
- deps: bytes@3.1.2
1.19.1 / 2021-12-10
===================
* deps: bytes@3.1.1
* deps: http-errors@1.8.1
- deps: inherits@2.0.4
- deps: toidentifier@1.0.1
- deps: setprototypeof@1.2.0
* deps: qs@6.9.6
* deps: raw-body@2.4.2
- deps: bytes@3.1.1
- deps: http-errors@1.8.1
* deps: safe-buffer@5.2.1
* deps: type-is@~1.6.18
1.19.0 / 2019-04-25
===================
* deps: bytes@3.1.0
- Add petabyte (`pb`) support
* deps: http-errors@1.7.2
- Set constructor name when possible
- deps: setprototypeof@1.1.1
- deps: statuses@'>= 1.5.0 < 2'
* deps: iconv-lite@0.4.24
- Added encoding MIK
* deps: qs@6.7.0
- Fix parsing array brackets after index
* deps: raw-body@2.4.0
- deps: bytes@3.1.0
- deps: http-errors@1.7.2
- deps: iconv-lite@0.4.24
* deps: type-is@~1.6.17
- deps: mime-types@~2.1.24
- perf: prevent internal `throw` on invalid type
1.18.3 / 2018-05-14
===================
* Fix stack trace for strict json parse error
* deps: depd@~1.1.2
- perf: remove argument reassignment
* deps: http-errors@~1.6.3
- deps: depd@~1.1.2
- deps: setprototypeof@1.1.0
- deps: statuses@'>= 1.3.1 < 2'
* deps: iconv-lite@0.4.23
- Fix loading encoding with year appended
- Fix deprecation warnings on Node.js 10+
* deps: qs@6.5.2
* deps: raw-body@2.3.3
- deps: http-errors@1.6.3
- deps: iconv-lite@0.4.23
* deps: type-is@~1.6.16
- deps: mime-types@~2.1.18
1.18.2 / 2017-09-22
===================
* deps: debug@2.6.9
* perf: remove argument reassignment
1.18.1 / 2017-09-12
===================
* deps: content-type@~1.0.4
- perf: remove argument reassignment
- perf: skip parameter parsing when no parameters
* deps: iconv-lite@0.4.19
- Fix ISO-8859-1 regression
- Update Windows-1255
* deps: qs@6.5.1
- Fix parsing & compacting very deep objects
* deps: raw-body@2.3.2
- deps: iconv-lite@0.4.19
1.18.0 / 2017-09-08
===================
* Fix JSON strict violation error to match native parse error
* Include the `body` property on verify errors
* Include the `type` property on all generated errors
* Use `http-errors` to set status code on errors
* deps: bytes@3.0.0
* deps: debug@2.6.8
* deps: depd@~1.1.1
- Remove unnecessary `Buffer` loading
* deps: http-errors@~1.6.2
- deps: depd@1.1.1
* deps: iconv-lite@0.4.18
- Add support for React Native
- Add a warning if not loaded as utf-8
- Fix CESU-8 decoding in Node.js 8
- Improve speed of ISO-8859-1 encoding
* deps: qs@6.5.0
* deps: raw-body@2.3.1
- Use `http-errors` for standard emitted errors
- deps: bytes@3.0.0
- deps: iconv-lite@0.4.18
- perf: skip buffer decoding on overage chunk
* perf: prevent internal `throw` when missing charset
1.17.2 / 2017-05-17
===================
* deps: debug@2.6.7
- Fix `DEBUG_MAX_ARRAY_LENGTH`
- deps: ms@2.0.0
* deps: type-is@~1.6.15
- deps: mime-types@~2.1.15
1.17.1 / 2017-03-06
===================
* deps: qs@6.4.0
- Fix regression parsing keys starting with `[`
1.17.0 / 2017-03-01
===================
* deps: http-errors@~1.6.1
- Make `message` property enumerable for `HttpError`s
- deps: setprototypeof@1.0.3
* deps: qs@6.3.1
- Fix compacting nested arrays
1.16.1 / 2017-02-10
===================
* deps: debug@2.6.1
- Fix deprecation messages in WebStorm and other editors
- Undeprecate `DEBUG_FD` set to `1` or `2`
1.16.0 / 2017-01-17
===================
* deps: debug@2.6.0
- Allow colors in workers
- Deprecated `DEBUG_FD` environment variable
- Fix error when running under React Native
- Use same color for same namespace
- deps: ms@0.7.2
* deps: http-errors@~1.5.1
- deps: inherits@2.0.3
- deps: setprototypeof@1.0.2
- deps: statuses@'>= 1.3.1 < 2'
* deps: iconv-lite@0.4.15
- Added encoding MS-31J
- Added encoding MS-932
- Added encoding MS-936
- Added encoding MS-949
- Added encoding MS-950
- Fix GBK/GB18030 handling of Euro character
* deps: qs@6.2.1
- Fix array parsing from skipping empty values
* deps: raw-body@~2.2.0
- deps: iconv-lite@0.4.15
* deps: type-is@~1.6.14
- deps: mime-types@~2.1.13
1.15.2 / 2016-06-19
===================
* deps: bytes@2.4.0
* deps: content-type@~1.0.2
- perf: enable strict mode
* deps: http-errors@~1.5.0
- Use `setprototypeof` module to replace `__proto__` setting
- deps: statuses@'>= 1.3.0 < 2'
- perf: enable strict mode
* deps: qs@6.2.0
* deps: raw-body@~2.1.7
- deps: bytes@2.4.0
- perf: remove double-cleanup on happy path
* deps: type-is@~1.6.13
- deps: mime-types@~2.1.11
1.15.1 / 2016-05-05
===================
* deps: bytes@2.3.0
- Drop partial bytes on all parsed units
- Fix parsing byte string that looks like hex
* deps: raw-body@~2.1.6
- deps: bytes@2.3.0
* deps: type-is@~1.6.12
- deps: mime-types@~2.1.10
1.15.0 / 2016-02-10
===================
* deps: http-errors@~1.4.0
- Add `HttpError` export, for `err instanceof createError.HttpError`
- deps: inherits@2.0.1
- deps: statuses@'>= 1.2.1 < 2'
* deps: qs@6.1.0
* deps: type-is@~1.6.11
- deps: mime-types@~2.1.9
1.14.2 / 2015-12-16
===================
* deps: bytes@2.2.0
* deps: iconv-lite@0.4.13
* deps: qs@5.2.0
* deps: raw-body@~2.1.5
- deps: bytes@2.2.0
- deps: iconv-lite@0.4.13
* deps: type-is@~1.6.10
- deps: mime-types@~2.1.8
1.14.1 / 2015-09-27
===================
* Fix issue where invalid charset results in 400 when `verify` used
* deps: iconv-lite@0.4.12
- Fix CESU-8 decoding in Node.js 4.x
* deps: raw-body@~2.1.4
- Fix masking critical errors from `iconv-lite`
- deps: iconv-lite@0.4.12
* deps: type-is@~1.6.9
- deps: mime-types@~2.1.7
1.14.0 / 2015-09-16
===================
* Fix JSON strict parse error to match syntax errors
* Provide static `require` analysis in `urlencoded` parser
* deps: depd@~1.1.0
- Support web browser loading
* deps: qs@5.1.0
* deps: raw-body@~2.1.3
- Fix sync callback when attaching data listener causes sync read
* deps: type-is@~1.6.8
- Fix type error when given invalid type to match against
- deps: mime-types@~2.1.6
1.13.3 / 2015-07-31
===================
* deps: type-is@~1.6.6
- deps: mime-types@~2.1.4
1.13.2 / 2015-07-05
===================
* deps: iconv-lite@0.4.11
* deps: qs@4.0.0
- Fix dropping parameters like `hasOwnProperty`
- Fix user-visible incompatibilities from 3.1.0
- Fix various parsing edge cases
* deps: raw-body@~2.1.2
- Fix error stack traces to skip `makeError`
- deps: iconv-lite@0.4.11
* deps: type-is@~1.6.4
- deps: mime-types@~2.1.2
- perf: enable strict mode
- perf: remove argument reassignment
1.13.1 / 2015-06-16
===================
* deps: qs@2.4.2
- Downgraded from 3.1.0 because of user-visible incompatibilities
1.13.0 / 2015-06-14
===================
* Add `statusCode` property on `Error`s, in addition to `status`
* Change `type` default to `application/json` for JSON parser
* Change `type` default to `application/x-www-form-urlencoded` for urlencoded parser
* Provide static `require` analysis
* Use the `http-errors` module to generate errors
* deps: bytes@2.1.0
- Slight optimizations
* deps: iconv-lite@0.4.10
- The encoding UTF-16 without BOM now defaults to UTF-16LE when detection fails
- Leading BOM is now removed when decoding
* deps: on-finished@~2.3.0
- Add defined behavior for HTTP `CONNECT` requests
- Add defined behavior for HTTP `Upgrade` requests
- deps: ee-first@1.1.1
* deps: qs@3.1.0
- Fix dropping parameters like `hasOwnProperty`
- Fix various parsing edge cases
- Parsed object now has `null` prototype
* deps: raw-body@~2.1.1
- Use `unpipe` module for unpiping requests
- deps: iconv-lite@0.4.10
* deps: type-is@~1.6.3
- deps: mime-types@~2.1.1
- perf: reduce try block size
- perf: remove bitwise operations
* perf: enable strict mode
* perf: remove argument reassignment
* perf: remove delete call
1.12.4 / 2015-05-10
===================
* deps: debug@~2.2.0
* deps: qs@2.4.2
- Fix allowing parameters like `constructor`
* deps: on-finished@~2.2.1
* deps: raw-body@~2.0.1
- Fix a false-positive when unpiping in Node.js 0.8
- deps: bytes@2.0.1
* deps: type-is@~1.6.2
- deps: mime-types@~2.0.11
1.12.3 / 2015-04-15
===================
* Slight efficiency improvement when not debugging
* deps: depd@~1.0.1
* deps: iconv-lite@0.4.8
- Add encoding alias UNICODE-1-1-UTF-7
* deps: raw-body@1.3.4
- Fix hanging callback if request aborts during read
- deps: iconv-lite@0.4.8
1.12.2 / 2015-03-16
===================
* deps: qs@2.4.1
- Fix error when parameter `hasOwnProperty` is present
1.12.1 / 2015-03-15
===================
* deps: debug@~2.1.3
- Fix high intensity foreground color for bold
- deps: ms@0.7.0
* deps: type-is@~1.6.1
- deps: mime-types@~2.0.10
1.12.0 / 2015-02-13
===================
* add `debug` messages
* accept a function for the `type` option
* use `content-type` to parse `Content-Type` headers
* deps: iconv-lite@0.4.7
- Gracefully support enumerables on `Object.prototype`
* deps: raw-body@1.3.3
- deps: iconv-lite@0.4.7
* deps: type-is@~1.6.0
- fix argument reassignment
- fix false-positives in `hasBody` `Transfer-Encoding` check
- support wildcard for both type and subtype (`*/*`)
- deps: mime-types@~2.0.9
1.11.0 / 2015-01-30
===================
* make internal `extended: true` depth limit infinity
* deps: type-is@~1.5.6
- deps: mime-types@~2.0.8
1.10.2 / 2015-01-20
===================
* deps: iconv-lite@0.4.6
- Fix rare aliases of single-byte encodings
* deps: raw-body@1.3.2
- deps: iconv-lite@0.4.6
1.10.1 / 2015-01-01
===================
* deps: on-finished@~2.2.0
* deps: type-is@~1.5.5
- deps: mime-types@~2.0.7
1.10.0 / 2014-12-02
===================
* make internal `extended: true` array limit dynamic
1.9.3 / 2014-11-21
==================
* deps: iconv-lite@0.4.5
- Fix Windows-31J and X-SJIS encoding support
* deps: qs@2.3.3
- Fix `arrayLimit` behavior
* deps: raw-body@1.3.1
- deps: iconv-lite@0.4.5
* deps: type-is@~1.5.3
- deps: mime-types@~2.0.3
1.9.2 / 2014-10-27
==================
* deps: qs@2.3.2
- Fix parsing of mixed objects and values
1.9.1 / 2014-10-22
==================
* deps: on-finished@~2.1.1
- Fix handling of pipelined requests
* deps: qs@2.3.0
- Fix parsing of mixed implicit and explicit arrays
* deps: type-is@~1.5.2
- deps: mime-types@~2.0.2
1.9.0 / 2014-09-24
==================
* include the charset in "unsupported charset" error message
* include the encoding in "unsupported content encoding" error message
* deps: depd@~1.0.0
1.8.4 / 2014-09-23
==================
* fix content encoding to be case-insensitive
1.8.3 / 2014-09-19
==================
* deps: qs@2.2.4
- Fix issue with object keys starting with numbers truncated
1.8.2 / 2014-09-15
==================
* deps: depd@0.4.5
1.8.1 / 2014-09-07
==================
* deps: media-typer@0.3.0
* deps: type-is@~1.5.1
1.8.0 / 2014-09-05
==================
* make empty-body-handling consistent between chunked requests
- empty `json` produces `{}`
- empty `raw` produces `new Buffer(0)`
- empty `text` produces `''`
- empty `urlencoded` produces `{}`
* deps: qs@2.2.3
- Fix issue where first empty value in array is discarded
* deps: type-is@~1.5.0
- fix `hasbody` to be true for `content-length: 0`
1.7.0 / 2014-09-01
==================
* add `parameterLimit` option to `urlencoded` parser
* change `urlencoded` extended array limit to 100
* respond with 413 when over `parameterLimit` in `urlencoded`
1.6.7 / 2014-08-29
==================
* deps: qs@2.2.2
- Remove unnecessary cloning
1.6.6 / 2014-08-27
==================
* deps: qs@2.2.0
- Array parsing fix
- Performance improvements
1.6.5 / 2014-08-16
==================
* deps: on-finished@2.1.0
1.6.4 / 2014-08-14
==================
* deps: qs@1.2.2
1.6.3 / 2014-08-10
==================
* deps: qs@1.2.1
1.6.2 / 2014-08-07
==================
* deps: qs@1.2.0
- Fix parsing array of objects
1.6.1 / 2014-08-06
==================
* deps: qs@1.1.0
- Accept urlencoded square brackets
- Accept empty values in implicit array notation
1.6.0 / 2014-08-05
==================
* deps: qs@1.0.2
- Complete rewrite
- Limits array length to 20
- Limits object depth to 5
- Limits parameters to 1,000
1.5.2 / 2014-07-27
==================
* deps: depd@0.4.4
- Work-around v8 generating empty stack traces
1.5.1 / 2014-07-26
==================
* deps: depd@0.4.3
- Fix exception when global `Error.stackTraceLimit` is too low
1.5.0 / 2014-07-20
==================
* deps: depd@0.4.2
- Add `TRACE_DEPRECATION` environment variable
- Remove non-standard grey color from color output
- Support `--no-deprecation` argument
- Support `--trace-deprecation` argument
* deps: iconv-lite@0.4.4
- Added encoding UTF-7
* deps: raw-body@1.3.0
- deps: iconv-lite@0.4.4
- Added encoding UTF-7
- Fix `Cannot switch to old mode now` error on Node.js 0.10+
* deps: type-is@~1.3.2
1.4.3 / 2014-06-19
==================
* deps: type-is@1.3.1
- fix global variable leak
1.4.2 / 2014-06-19
==================
* deps: type-is@1.3.0
- improve type parsing
1.4.1 / 2014-06-19
==================
* fix urlencoded extended deprecation message
1.4.0 / 2014-06-19
==================
* add `text` parser
* add `raw` parser
* check accepted charset in content-type (accepts utf-8)
* check accepted encoding in content-encoding (accepts identity)
* deprecate `bodyParser()` middleware; use `.json()` and `.urlencoded()` as needed
* deprecate `urlencoded()` without provided `extended` option
* lazy-load urlencoded parsers
* parsers split into files for reduced mem usage
* support gzip and deflate bodies
- set `inflate: false` to turn off
* deps: raw-body@1.2.2
- Support all encodings from `iconv-lite`
1.3.1 / 2014-06-11
==================
* deps: type-is@1.2.1
- Switch dependency from mime to mime-types@1.0.0
1.3.0 / 2014-05-31
==================
* add `extended` option to urlencoded parser
1.2.2 / 2014-05-27
==================
* deps: raw-body@1.1.6
- assert stream encoding on node.js 0.8
- assert stream encoding on node.js < 0.10.6
- deps: bytes@1
1.2.1 / 2014-05-26
==================
* invoke `next(err)` after request fully read
- prevents hung responses and socket hang ups
1.2.0 / 2014-05-11
==================
* add `verify` option
* deps: type-is@1.2.0
- support suffix matching
1.1.2 / 2014-05-11
==================
* improve json parser speed
1.1.1 / 2014-05-11
==================
* fix repeated limit parsing with every request
1.1.0 / 2014-05-10
==================
* add `type` option
* deps: pin for safety and consistency
1.0.2 / 2014-04-14
==================
* use `type-is` module
1.0.1 / 2014-03-20
==================
* lower default limits to 100kb

View File

@@ -1,23 +0,0 @@
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,476 +0,0 @@
# body-parser
[![NPM Version][npm-version-image]][npm-url]
[![NPM Downloads][npm-downloads-image]][npm-url]
[![Build Status][ci-image]][ci-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![OpenSSF Scorecard Badge][ossf-scorecard-badge]][ossf-scorecard-visualizer]
Node.js body parsing middleware.
Parse incoming request bodies in a middleware before your handlers, available
under the `req.body` property.
**Note** As `req.body`'s shape is based on user-controlled input, all
properties and values in this object are untrusted and should be validated
before trusting. For example, `req.body.foo.toString()` may fail in multiple
ways, for example the `foo` property may not be there or may not be a string,
and `toString` may not be a function and instead a string or other user input.
[Learn about the anatomy of an HTTP transaction in Node.js](https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/).
_This does not handle multipart bodies_, due to their complex and typically
large nature. For multipart bodies, you may be interested in the following
modules:
* [busboy](https://www.npmjs.org/package/busboy#readme) and
[connect-busboy](https://www.npmjs.org/package/connect-busboy#readme)
* [multiparty](https://www.npmjs.org/package/multiparty#readme) and
[connect-multiparty](https://www.npmjs.org/package/connect-multiparty#readme)
* [formidable](https://www.npmjs.org/package/formidable#readme)
* [multer](https://www.npmjs.org/package/multer#readme)
This module provides the following parsers:
* [JSON body parser](#bodyparserjsonoptions)
* [Raw body parser](#bodyparserrawoptions)
* [Text body parser](#bodyparsertextoptions)
* [URL-encoded form body parser](#bodyparserurlencodedoptions)
Other body parsers you might be interested in:
- [body](https://www.npmjs.org/package/body#readme)
- [co-body](https://www.npmjs.org/package/co-body#readme)
## Installation
```sh
$ npm install body-parser
```
## API
```js
var bodyParser = require('body-parser')
```
The `bodyParser` object exposes various factories to create middlewares. All
middlewares will populate the `req.body` property with the parsed body when
the `Content-Type` request header matches the `type` option, or an empty
object (`{}`) if there was no body to parse, the `Content-Type` was not matched,
or an error occurred.
The various errors returned by this module are described in the
[errors section](#errors).
### bodyParser.json([options])
Returns middleware that only parses `json` and only looks at requests where
the `Content-Type` header matches the `type` option. This parser accepts any
Unicode encoding of the body and supports automatic inflation of `gzip` and
`deflate` encodings.
A new `body` object containing the parsed data is populated on the `request`
object after the middleware (i.e. `req.body`).
#### Options
The `json` function takes an optional `options` object that may contain any of
the following keys:
##### inflate
When set to `true`, then deflated (compressed) bodies will be inflated; when
`false`, deflated bodies are rejected. Defaults to `true`.
##### limit
Controls the maximum request body size. If this is a number, then the value
specifies the number of bytes; if it is a string, the value is passed to the
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults
to `'100kb'`.
##### reviver
The `reviver` option is passed directly to `JSON.parse` as the second
argument. You can find more information on this argument
[in the MDN documentation about JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter).
##### strict
When set to `true`, will only accept arrays and objects; when `false` will
accept anything `JSON.parse` accepts. Defaults to `true`.
##### type
The `type` option is used to determine what media type the middleware will
parse. This option can be a string, array of strings, or a function. If not a
function, `type` option is passed directly to the
[type-is](https://www.npmjs.org/package/type-is#readme) library and this can
be an extension name (like `json`), a mime type (like `application/json`), or
a mime type with a wildcard (like `*/*` or `*/json`). If a function, the `type`
option is called as `fn(req)` and the request is parsed if it returns a truthy
value. Defaults to `application/json`.
##### verify
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`,
where `buf` is a `Buffer` of the raw request body and `encoding` is the
encoding of the request. The parsing can be aborted by throwing an error.
### bodyParser.raw([options])
Returns middleware that parses all bodies as a `Buffer` and only looks at
requests where the `Content-Type` header matches the `type` option. This
parser supports automatic inflation of `gzip` and `deflate` encodings.
A new `body` object containing the parsed data is populated on the `request`
object after the middleware (i.e. `req.body`). This will be a `Buffer` object
of the body.
#### Options
The `raw` function takes an optional `options` object that may contain any of
the following keys:
##### inflate
When set to `true`, then deflated (compressed) bodies will be inflated; when
`false`, deflated bodies are rejected. Defaults to `true`.
##### limit
Controls the maximum request body size. If this is a number, then the value
specifies the number of bytes; if it is a string, the value is passed to the
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults
to `'100kb'`.
##### type
The `type` option is used to determine what media type the middleware will
parse. This option can be a string, array of strings, or a function.
If not a function, `type` option is passed directly to the
[type-is](https://www.npmjs.org/package/type-is#readme) library and this
can be an extension name (like `bin`), a mime type (like
`application/octet-stream`), or a mime type with a wildcard (like `*/*` or
`application/*`). If a function, the `type` option is called as `fn(req)`
and the request is parsed if it returns a truthy value. Defaults to
`application/octet-stream`.
##### verify
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`,
where `buf` is a `Buffer` of the raw request body and `encoding` is the
encoding of the request. The parsing can be aborted by throwing an error.
### bodyParser.text([options])
Returns middleware that parses all bodies as a string and only looks at
requests where the `Content-Type` header matches the `type` option. This
parser supports automatic inflation of `gzip` and `deflate` encodings.
A new `body` string containing the parsed data is populated on the `request`
object after the middleware (i.e. `req.body`). This will be a string of the
body.
#### Options
The `text` function takes an optional `options` object that may contain any of
the following keys:
##### defaultCharset
Specify the default character set for the text content if the charset is not
specified in the `Content-Type` header of the request. Defaults to `utf-8`.
##### inflate
When set to `true`, then deflated (compressed) bodies will be inflated; when
`false`, deflated bodies are rejected. Defaults to `true`.
##### limit
Controls the maximum request body size. If this is a number, then the value
specifies the number of bytes; if it is a string, the value is passed to the
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults
to `'100kb'`.
##### type
The `type` option is used to determine what media type the middleware will
parse. This option can be a string, array of strings, or a function. If not
a function, `type` option is passed directly to the
[type-is](https://www.npmjs.org/package/type-is#readme) library and this can
be an extension name (like `txt`), a mime type (like `text/plain`), or a mime
type with a wildcard (like `*/*` or `text/*`). If a function, the `type`
option is called as `fn(req)` and the request is parsed if it returns a
truthy value. Defaults to `text/plain`.
##### verify
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`,
where `buf` is a `Buffer` of the raw request body and `encoding` is the
encoding of the request. The parsing can be aborted by throwing an error.
### bodyParser.urlencoded([options])
Returns middleware that only parses `urlencoded` bodies and only looks at
requests where the `Content-Type` header matches the `type` option. This
parser accepts only UTF-8 encoding of the body and supports automatic
inflation of `gzip` and `deflate` encodings.
A new `body` object containing the parsed data is populated on the `request`
object after the middleware (i.e. `req.body`). This object will contain
key-value pairs, where the value can be a string or array (when `extended` is
`false`), or any type (when `extended` is `true`).
#### Options
The `urlencoded` function takes an optional `options` object that may contain
any of the following keys:
##### extended
The `extended` option allows to choose between parsing the URL-encoded data
with the `querystring` library (when `false`) or the `qs` library (when
`true`). The "extended" syntax allows for rich objects and arrays to be
encoded into the URL-encoded format, allowing for a JSON-like experience
with URL-encoded. For more information, please
[see the qs library](https://www.npmjs.org/package/qs#readme).
Defaults to `true`, but using the default has been deprecated. Please
research into the difference between `qs` and `querystring` and choose the
appropriate setting.
##### inflate
When set to `true`, then deflated (compressed) bodies will be inflated; when
`false`, deflated bodies are rejected. Defaults to `true`.
##### limit
Controls the maximum request body size. If this is a number, then the value
specifies the number of bytes; if it is a string, the value is passed to the
[bytes](https://www.npmjs.com/package/bytes) library for parsing. Defaults
to `'100kb'`.
##### parameterLimit
The `parameterLimit` option controls the maximum number of parameters that
are allowed in the URL-encoded data. If a request contains more parameters
than this value, a 413 will be returned to the client. Defaults to `1000`.
##### type
The `type` option is used to determine what media type the middleware will
parse. This option can be a string, array of strings, or a function. If not
a function, `type` option is passed directly to the
[type-is](https://www.npmjs.org/package/type-is#readme) library and this can
be an extension name (like `urlencoded`), a mime type (like
`application/x-www-form-urlencoded`), or a mime type with a wildcard (like
`*/x-www-form-urlencoded`). If a function, the `type` option is called as
`fn(req)` and the request is parsed if it returns a truthy value. Defaults
to `application/x-www-form-urlencoded`.
##### verify
The `verify` option, if supplied, is called as `verify(req, res, buf, encoding)`,
where `buf` is a `Buffer` of the raw request body and `encoding` is the
encoding of the request. The parsing can be aborted by throwing an error.
#### depth
The `depth` option is used to configure the maximum depth of the `qs` library when `extended` is `true`. This allows you to limit the amount of keys that are parsed and can be useful to prevent certain types of abuse. Defaults to `32`. It is recommended to keep this value as low as possible.
## Errors
The middlewares provided by this module create errors using the
[`http-errors` module](https://www.npmjs.com/package/http-errors). The errors
will typically have a `status`/`statusCode` property that contains the suggested
HTTP response code, an `expose` property to determine if the `message` property
should be displayed to the client, a `type` property to determine the type of
error without matching against the `message`, and a `body` property containing
the read body, if available.
The following are the common errors created, though any error can come through
for various reasons.
### content encoding unsupported
This error will occur when the request had a `Content-Encoding` header that
contained an encoding but the "inflation" option was set to `false`. The
`status` property is set to `415`, the `type` property is set to
`'encoding.unsupported'`, and the `charset` property will be set to the
encoding that is unsupported.
### entity parse failed
This error will occur when the request contained an entity that could not be
parsed by the middleware. The `status` property is set to `400`, the `type`
property is set to `'entity.parse.failed'`, and the `body` property is set to
the entity value that failed parsing.
### entity verify failed
This error will occur when the request contained an entity that could not be
failed verification by the defined `verify` option. The `status` property is
set to `403`, the `type` property is set to `'entity.verify.failed'`, and the
`body` property is set to the entity value that failed verification.
### request aborted
This error will occur when the request is aborted by the client before reading
the body has finished. The `received` property will be set to the number of
bytes received before the request was aborted and the `expected` property is
set to the number of expected bytes. The `status` property is set to `400`
and `type` property is set to `'request.aborted'`.
### request entity too large
This error will occur when the request body's size is larger than the "limit"
option. The `limit` property will be set to the byte limit and the `length`
property will be set to the request body's length. The `status` property is
set to `413` and the `type` property is set to `'entity.too.large'`.
### request size did not match content length
This error will occur when the request's length did not match the length from
the `Content-Length` header. This typically occurs when the request is malformed,
typically when the `Content-Length` header was calculated based on characters
instead of bytes. The `status` property is set to `400` and the `type` property
is set to `'request.size.invalid'`.
### stream encoding should not be set
This error will occur when something called the `req.setEncoding` method prior
to this middleware. This module operates directly on bytes only and you cannot
call `req.setEncoding` when using this module. The `status` property is set to
`500` and the `type` property is set to `'stream.encoding.set'`.
### stream is not readable
This error will occur when the request is no longer readable when this middleware
attempts to read it. This typically means something other than a middleware from
this module read the request body already and the middleware was also configured to
read the same request. The `status` property is set to `500` and the `type`
property is set to `'stream.not.readable'`.
### too many parameters
This error will occur when the content of the request exceeds the configured
`parameterLimit` for the `urlencoded` parser. The `status` property is set to
`413` and the `type` property is set to `'parameters.too.many'`.
### unsupported charset "BOGUS"
This error will occur when the request had a charset parameter in the
`Content-Type` header, but the `iconv-lite` module does not support it OR the
parser does not support it. The charset is contained in the message as well
as in the `charset` property. The `status` property is set to `415`, the
`type` property is set to `'charset.unsupported'`, and the `charset` property
is set to the charset that is unsupported.
### unsupported content encoding "bogus"
This error will occur when the request had a `Content-Encoding` header that
contained an unsupported encoding. The encoding is contained in the message
as well as in the `encoding` property. The `status` property is set to `415`,
the `type` property is set to `'encoding.unsupported'`, and the `encoding`
property is set to the encoding that is unsupported.
### The input exceeded the depth
This error occurs when using `bodyParser.urlencoded` with the `extended` property set to `true` and the input exceeds the configured `depth` option. The `status` property is set to `400`. It is recommended to review the `depth` option and evaluate if it requires a higher value. When the `depth` option is set to `32` (default value), the error will not be thrown.
## Examples
### Express/Connect top-level generic
This example demonstrates adding a generic JSON and URL-encoded parser as a
top-level middleware, which will parse the bodies of all incoming requests.
This is the simplest setup.
```js
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(function (req, res) {
res.setHeader('Content-Type', 'text/plain')
res.write('you posted:\n')
res.end(JSON.stringify(req.body, null, 2))
})
```
### Express route-specific
This example demonstrates adding body parsers specifically to the routes that
need them. In general, this is the most recommended way to use body-parser with
Express.
```js
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// create application/json parser
var jsonParser = bodyParser.json()
// create application/x-www-form-urlencoded parser
var urlencodedParser = bodyParser.urlencoded({ extended: false })
// POST /login gets urlencoded bodies
app.post('/login', urlencodedParser, function (req, res) {
res.send('welcome, ' + req.body.username)
})
// POST /api/users gets JSON bodies
app.post('/api/users', jsonParser, function (req, res) {
// create user in req.body
})
```
### Change accepted type for parsers
All the parsers accept a `type` option which allows you to change the
`Content-Type` that the middleware will parse.
```js
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// parse various different custom JSON types as JSON
app.use(bodyParser.json({ type: 'application/*+json' }))
// parse some custom thing into a Buffer
app.use(bodyParser.raw({ type: 'application/vnd.custom-type' }))
// parse an HTML body into a string
app.use(bodyParser.text({ type: 'text/html' }))
```
## License
[MIT](LICENSE)
[ci-image]: https://badgen.net/github/checks/expressjs/body-parser/master?label=ci
[ci-url]: https://github.com/expressjs/body-parser/actions/workflows/ci.yml
[coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/body-parser/master
[coveralls-url]: https://coveralls.io/r/expressjs/body-parser?branch=master
[node-version-image]: https://badgen.net/npm/node/body-parser
[node-version-url]: https://nodejs.org/en/download
[npm-downloads-image]: https://badgen.net/npm/dm/body-parser
[npm-url]: https://npmjs.org/package/body-parser
[npm-version-image]: https://badgen.net/npm/v/body-parser
[ossf-scorecard-badge]: https://api.scorecard.dev/projects/github.com/expressjs/body-parser/badge
[ossf-scorecard-visualizer]: https://ossf.github.io/scorecard-visualizer/#/projects/github.com/expressjs/body-parser

View File

@@ -1,25 +0,0 @@
# Security Policies and Procedures
## Reporting a Bug
The Express team and community take all security bugs seriously. Thank you
for improving the security of Express. We appreciate your efforts and
responsible disclosure and will make every effort to acknowledge your
contributions.
Report security bugs by emailing the current owner(s) of `body-parser`. This
information can be found in the npm registry using the command
`npm owner ls body-parser`.
If unsure or unable to get the information from the above, open an issue
in the [project issue tracker](https://github.com/expressjs/body-parser/issues)
asking for the current contact information.
To ensure the timely response to your report, please ensure that the entirety
of the report is contained within the email body and not solely behind a web
link or an attachment.
At least one owner will acknowledge your email within 48 hours, and will send a
more detailed response within 48 hours indicating the next steps in handling
your report. After the initial reply to your report, the owners will
endeavor to keep you informed of the progress towards a fix and full
announcement, and may ask for additional information or guidance.

View File

@@ -1,156 +0,0 @@
/*!
* body-parser
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var deprecate = require('depd')('body-parser')
/**
* Cache of loaded parsers.
* @private
*/
var parsers = Object.create(null)
/**
* @typedef Parsers
* @type {function}
* @property {function} json
* @property {function} raw
* @property {function} text
* @property {function} urlencoded
*/
/**
* Module exports.
* @type {Parsers}
*/
exports = module.exports = deprecate.function(bodyParser,
'bodyParser: use individual json/urlencoded middlewares')
/**
* JSON parser.
* @public
*/
Object.defineProperty(exports, 'json', {
configurable: true,
enumerable: true,
get: createParserGetter('json')
})
/**
* Raw parser.
* @public
*/
Object.defineProperty(exports, 'raw', {
configurable: true,
enumerable: true,
get: createParserGetter('raw')
})
/**
* Text parser.
* @public
*/
Object.defineProperty(exports, 'text', {
configurable: true,
enumerable: true,
get: createParserGetter('text')
})
/**
* URL-encoded parser.
* @public
*/
Object.defineProperty(exports, 'urlencoded', {
configurable: true,
enumerable: true,
get: createParserGetter('urlencoded')
})
/**
* Create a middleware to parse json and urlencoded bodies.
*
* @param {object} [options]
* @return {function}
* @deprecated
* @public
*/
function bodyParser (options) {
// use default type for parsers
var opts = Object.create(options || null, {
type: {
configurable: true,
enumerable: true,
value: undefined,
writable: true
}
})
var _urlencoded = exports.urlencoded(opts)
var _json = exports.json(opts)
return function bodyParser (req, res, next) {
_json(req, res, function (err) {
if (err) return next(err)
_urlencoded(req, res, next)
})
}
}
/**
* Create a getter for loading a parser.
* @private
*/
function createParserGetter (name) {
return function get () {
return loadParser(name)
}
}
/**
* Load a parser module.
* @private
*/
function loadParser (parserName) {
var parser = parsers[parserName]
if (parser !== undefined) {
return parser
}
// this uses a switch for static require analysis
switch (parserName) {
case 'json':
parser = require('./lib/types/json')
break
case 'raw':
parser = require('./lib/types/raw')
break
case 'text':
parser = require('./lib/types/text')
break
case 'urlencoded':
parser = require('./lib/types/urlencoded')
break
}
// store to prevent invoking require()
return (parsers[parserName] = parser)
}

View File

@@ -1,205 +0,0 @@
/*!
* body-parser
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var createError = require('http-errors')
var destroy = require('destroy')
var getBody = require('raw-body')
var iconv = require('iconv-lite')
var onFinished = require('on-finished')
var unpipe = require('unpipe')
var zlib = require('zlib')
/**
* Module exports.
*/
module.exports = read
/**
* Read a request into a buffer and parse.
*
* @param {object} req
* @param {object} res
* @param {function} next
* @param {function} parse
* @param {function} debug
* @param {object} options
* @private
*/
function read (req, res, next, parse, debug, options) {
var length
var opts = options
var stream
// flag as parsed
req._body = true
// read options
var encoding = opts.encoding !== null
? opts.encoding
: null
var verify = opts.verify
try {
// get the content stream
stream = contentstream(req, debug, opts.inflate)
length = stream.length
stream.length = undefined
} catch (err) {
return next(err)
}
// set raw-body options
opts.length = length
opts.encoding = verify
? null
: encoding
// assert charset is supported
if (opts.encoding === null && encoding !== null && !iconv.encodingExists(encoding)) {
return next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
charset: encoding.toLowerCase(),
type: 'charset.unsupported'
}))
}
// read body
debug('read body')
getBody(stream, opts, function (error, body) {
if (error) {
var _error
if (error.type === 'encoding.unsupported') {
// echo back charset
_error = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
charset: encoding.toLowerCase(),
type: 'charset.unsupported'
})
} else {
// set status code on error
_error = createError(400, error)
}
// unpipe from stream and destroy
if (stream !== req) {
unpipe(req)
destroy(stream, true)
}
// read off entire request
dump(req, function onfinished () {
next(createError(400, _error))
})
return
}
// verify
if (verify) {
try {
debug('verify body')
verify(req, res, body, encoding)
} catch (err) {
next(createError(403, err, {
body: body,
type: err.type || 'entity.verify.failed'
}))
return
}
}
// parse
var str = body
try {
debug('parse body')
str = typeof body !== 'string' && encoding !== null
? iconv.decode(body, encoding)
: body
req.body = parse(str)
} catch (err) {
next(createError(400, err, {
body: str,
type: err.type || 'entity.parse.failed'
}))
return
}
next()
})
}
/**
* Get the content stream of the request.
*
* @param {object} req
* @param {function} debug
* @param {boolean} [inflate=true]
* @return {object}
* @api private
*/
function contentstream (req, debug, inflate) {
var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase()
var length = req.headers['content-length']
var stream
debug('content-encoding "%s"', encoding)
if (inflate === false && encoding !== 'identity') {
throw createError(415, 'content encoding unsupported', {
encoding: encoding,
type: 'encoding.unsupported'
})
}
switch (encoding) {
case 'deflate':
stream = zlib.createInflate()
debug('inflate body')
req.pipe(stream)
break
case 'gzip':
stream = zlib.createGunzip()
debug('gunzip body')
req.pipe(stream)
break
case 'identity':
stream = req
stream.length = length
break
default:
throw createError(415, 'unsupported content encoding "' + encoding + '"', {
encoding: encoding,
type: 'encoding.unsupported'
})
}
return stream
}
/**
* Dump the contents of a request.
*
* @param {object} req
* @param {function} callback
* @api private
*/
function dump (req, callback) {
if (onFinished.isFinished(req)) {
callback(null)
} else {
onFinished(req, callback)
req.resume()
}
}

View File

@@ -1,247 +0,0 @@
/*!
* body-parser
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
* @private
*/
var bytes = require('bytes')
var contentType = require('content-type')
var createError = require('http-errors')
var debug = require('debug')('body-parser:json')
var read = require('../read')
var typeis = require('type-is')
/**
* Module exports.
*/
module.exports = json
/**
* RegExp to match the first non-space in a string.
*
* Allowed whitespace is defined in RFC 7159:
*
* ws = *(
* %x20 / ; Space
* %x09 / ; Horizontal tab
* %x0A / ; Line feed or New line
* %x0D ) ; Carriage return
*/
var FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/ // eslint-disable-line no-control-regex
var JSON_SYNTAX_CHAR = '#'
var JSON_SYNTAX_REGEXP = /#+/g
/**
* Create a middleware to parse JSON bodies.
*
* @param {object} [options]
* @return {function}
* @public
*/
function json (options) {
var opts = options || {}
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var inflate = opts.inflate !== false
var reviver = opts.reviver
var strict = opts.strict !== false
var type = opts.type || 'application/json'
var verify = opts.verify || false
if (verify !== false && typeof verify !== 'function') {
throw new TypeError('option verify must be function')
}
// create the appropriate type checking function
var shouldParse = typeof type !== 'function'
? typeChecker(type)
: type
function parse (body) {
if (body.length === 0) {
// special-case empty json body, as it's a common client-side mistake
// TODO: maybe make this configurable or part of "strict" option
return {}
}
if (strict) {
var first = firstchar(body)
if (first !== '{' && first !== '[') {
debug('strict violation')
throw createStrictSyntaxError(body, first)
}
}
try {
debug('parse json')
return JSON.parse(body, reviver)
} catch (e) {
throw normalizeJsonSyntaxError(e, {
message: e.message,
stack: e.stack
})
}
}
return function jsonParser (req, res, next) {
if (req._body) {
debug('body already parsed')
next()
return
}
req.body = req.body || {}
// skip requests without bodies
if (!typeis.hasBody(req)) {
debug('skip empty body')
next()
return
}
debug('content-type %j', req.headers['content-type'])
// determine if request should be parsed
if (!shouldParse(req)) {
debug('skip parsing')
next()
return
}
// assert charset per RFC 7159 sec 8.1
var charset = getCharset(req) || 'utf-8'
if (charset.slice(0, 4) !== 'utf-') {
debug('invalid charset')
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
charset: charset,
type: 'charset.unsupported'
}))
return
}
// read
read(req, res, next, parse, debug, {
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify
})
}
}
/**
* Create strict violation syntax error matching native error.
*
* @param {string} str
* @param {string} char
* @return {Error}
* @private
*/
function createStrictSyntaxError (str, char) {
var index = str.indexOf(char)
var partial = ''
if (index !== -1) {
partial = str.substring(0, index) + JSON_SYNTAX_CHAR
for (var i = index + 1; i < str.length; i++) {
partial += JSON_SYNTAX_CHAR
}
}
try {
JSON.parse(partial); /* istanbul ignore next */ throw new SyntaxError('strict violation')
} catch (e) {
return normalizeJsonSyntaxError(e, {
message: e.message.replace(JSON_SYNTAX_REGEXP, function (placeholder) {
return str.substring(index, index + placeholder.length)
}),
stack: e.stack
})
}
}
/**
* Get the first non-whitespace character in a string.
*
* @param {string} str
* @return {function}
* @private
*/
function firstchar (str) {
var match = FIRST_CHAR_REGEXP.exec(str)
return match
? match[1]
: undefined
}
/**
* Get the charset of a request.
*
* @param {object} req
* @api private
*/
function getCharset (req) {
try {
return (contentType.parse(req).parameters.charset || '').toLowerCase()
} catch (e) {
return undefined
}
}
/**
* Normalize a SyntaxError for JSON.parse.
*
* @param {SyntaxError} error
* @param {object} obj
* @return {SyntaxError}
*/
function normalizeJsonSyntaxError (error, obj) {
var keys = Object.getOwnPropertyNames(error)
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
if (key !== 'stack' && key !== 'message') {
delete error[key]
}
}
// replace stack before message for Node.js 0.10 and below
error.stack = obj.stack.replace(error.message, obj.message)
error.message = obj.message
return error
}
/**
* Get the simple type checker.
*
* @param {string} type
* @return {function}
*/
function typeChecker (type) {
return function checkType (req) {
return Boolean(typeis(req, type))
}
}

View File

@@ -1,101 +0,0 @@
/*!
* body-parser
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
*/
var bytes = require('bytes')
var debug = require('debug')('body-parser:raw')
var read = require('../read')
var typeis = require('type-is')
/**
* Module exports.
*/
module.exports = raw
/**
* Create a middleware to parse raw bodies.
*
* @param {object} [options]
* @return {function}
* @api public
*/
function raw (options) {
var opts = options || {}
var inflate = opts.inflate !== false
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var type = opts.type || 'application/octet-stream'
var verify = opts.verify || false
if (verify !== false && typeof verify !== 'function') {
throw new TypeError('option verify must be function')
}
// create the appropriate type checking function
var shouldParse = typeof type !== 'function'
? typeChecker(type)
: type
function parse (buf) {
return buf
}
return function rawParser (req, res, next) {
if (req._body) {
debug('body already parsed')
next()
return
}
req.body = req.body || {}
// skip requests without bodies
if (!typeis.hasBody(req)) {
debug('skip empty body')
next()
return
}
debug('content-type %j', req.headers['content-type'])
// determine if request should be parsed
if (!shouldParse(req)) {
debug('skip parsing')
next()
return
}
// read
read(req, res, next, parse, debug, {
encoding: null,
inflate: inflate,
limit: limit,
verify: verify
})
}
}
/**
* Get the simple type checker.
*
* @param {string} type
* @return {function}
*/
function typeChecker (type) {
return function checkType (req) {
return Boolean(typeis(req, type))
}
}

View File

@@ -1,121 +0,0 @@
/*!
* body-parser
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict'
/**
* Module dependencies.
*/
var bytes = require('bytes')
var contentType = require('content-type')
var debug = require('debug')('body-parser:text')
var read = require('../read')
var typeis = require('type-is')
/**
* Module exports.
*/
module.exports = text
/**
* Create a middleware to parse text bodies.
*
* @param {object} [options]
* @return {function}
* @api public
*/
function text (options) {
var opts = options || {}
var defaultCharset = opts.defaultCharset || 'utf-8'
var inflate = opts.inflate !== false
var limit = typeof opts.limit !== 'number'
? bytes.parse(opts.limit || '100kb')
: opts.limit
var type = opts.type || 'text/plain'
var verify = opts.verify || false
if (verify !== false && typeof verify !== 'function') {
throw new TypeError('option verify must be function')
}
// create the appropriate type checking function
var shouldParse = typeof type !== 'function'
? typeChecker(type)
: type
function parse (buf) {
return buf
}
return function textParser (req, res, next) {
if (req._body) {
debug('body already parsed')
next()
return
}
req.body = req.body || {}
// skip requests without bodies
if (!typeis.hasBody(req)) {
debug('skip empty body')
next()
return
}
debug('content-type %j', req.headers['content-type'])
// determine if request should be parsed
if (!shouldParse(req)) {
debug('skip parsing')
next()
return
}
// get charset
var charset = getCharset(req) || defaultCharset
// read
read(req, res, next, parse, debug, {
encoding: charset,
inflate: inflate,
limit: limit,
verify: verify
})
}
}
/**
* Get the charset of a request.
*
* @param {object} req
* @api private
*/
function getCharset (req) {
try {
return (contentType.parse(req).parameters.charset || '').toLowerCase()
} catch (e) {
return undefined
}
}
/**
* Get the simple type checker.
*
* @param {string} type
* @return {function}
*/
function typeChecker (type) {
return function checkType (req) {
return Boolean(typeis(req, type))
}
}

Some files were not shown because too many files have changed in this diff Show More