text: const sessions = require('../data/sessions');
  const fUtil = require('../fileUtil');
  const stuff = require('./info');
  
  function toAttrString(table) {
  	return typeof (table) == 'object' ? Object.keys(table).filter(key => table[key] !== null).map(key =>
  		`${encodeURIComponent(key)}=${encodeURIComponent(table[key])}`).join('&') : table.replace(/"/g, "\\\"");
  }
  function toParamString(table) {
  	return Object.keys(table).map(key =>
  		`<param name="${key}" value="${toAttrString(table[key])}">`
  	).join(' ');
  }
  function toObjectString(attrs, params) {
  	return `<object ${Object.keys(attrs).map(key =>
  		`${key}="${attrs[key].replace(/"/g, "\\\"")}"`
  	).join(' ')}>${toParamString(params)}</object>`;
  }
  
  module.exports = function (req, res, url) {
  	if (req.method != 'GET') return;
  	const query = url.query;
  
  	var attrs, params, title;
  	switch (url.pathname) {
  		case '/cc': {
  			title = 'Character Creator';
  			attrs = {
  				data: process.env.SWF_URL + '/cc.swf', // data: 'cc.swf',
  				type: 'application/x-shockwave-flash', id: 'char_creator', width: '100%', height: '100%',
  			};
  			params = {
  				flashvars: {
  					'apiserver': '/', 'storePath': process.env.STORE_URL + '/<store>',
  					'clientThemePath': process.env.CLIENT_URL + '/<client_theme>', 'original_asset_id': query['id'] || null,
  					'themeId': 'family', 'bs': 'adam', 'ut': 23, 'bs': 'default', 'appCode': 'go', 'page': '', 'siteId': 'go',
  					'm_mode': 'school', 'isLogin': 'Y', 'isEmbed': 1, 'ctc': 'go', 'tlang': 'en_US',
  				},
  				allowScriptAccess: 'always',
  				movie: process.env.SWF_URL + '/cc.swf', // 'http://localhost/cc.swf'
  			};
  			break;
  		}
  			
                  case '/cc_browser': {
  			title = 'CC Browser';
  			attrs = {
  				data: process.env.SWF_URL + '/cc_browser.swf', // data: 'cc_browser.swf',
  				type: 'application/x-shockwave-flash', id: 'ccbrowser', width: '100%', height: '100%',
  			};
  			params = {
  				flashvars: {
  					'apiserver': '/', 'isEmbed': '0', 'ctc': 'go', 'tlang': 'en_US', 
  					'storePath': process.env.STORE_URL + '/<store>', 
  					'clientThemePath': process.env.CLIENT_URL + '/<client_theme>', 'appCode': 'go', 'siteId': 'school', 'st': '', 
  					'userId': '0DyHqK6Yj9dM', 'ut': 23, 'uisa': 0, 'themeId': 'family', 
  					'u_info_school': 'OjI6d1lZakM3SVUxak5YVU9rQWlueURFZ3ZTT1EwakFJYjczcGVCMzJTMiszcFYzVERQRDByQktlUElUTDlaeUdsSzJyRTZFZldHMVRXR1BtOTNwWm5vS2JscTFXTzVodndrVnpaRG9XNVppRU9pSnRpR3pnSEljPQ==',
  				},
  
  				allowScriptAccess: 'always',
  				movie: process.env.SWF_URL + '/cc_browser.swf', // 'http://localhost/cc_browser.swf'
  			};
  			break;
  		}
  			
  		case '/go_full': {
  			let presave = query.movieId && query.movieId.startsWith('m') ? query.movieId :
  				`m-${fUtil[query.noAutosave ? 'getNextFileId' : 'fillNextFileId']('movie-', '.xml')}`;
  			title = 'Video Editor';
  			attrs = {
  				data: process.env.SWF_URL + '/go_full.swf',
  				type: 'application/x-shockwave-flash', id: 'Studio', width: '100%', height: '100%',
  			};
  			params = {
  				flashvars: {
  					'apiserver': '/', 'storePath': process.env.STORE_URL + '/<store>', 'isEmbed': 1, 'ctc': 'go',
  					'ut': 23, 'bs': 'default', 'appCode': 'go', 'page': '', 'siteId': 'go', 'lid': 13, 'isLogin': 'Y', 'retut': 1,
  					'clientThemePath': process.env.CLIENT_URL + '/<client_theme>', 'themeId': 'business', 'tray': 'custom', 'tlang': 'en_US',
  					'presaveId': presave, 'goteam_draft_only': 1, 'isWide': 1, 'nextUrl': '/html/list.html',
  				},
  				allowScriptAccess: 'always',
  				movie: process.env.SWF_URL + '/go_full.swf', // 'http://localhost/go_full.swf'
  			};
  			sessions.set({ movieId: presave }, req);
  			break;
  		}
  
  		case '/player': {
  			title = 'Player';
  			attrs = {
  				data: process.env.SWF_URL + '/player.swf',
  				type: 'application/x-shockwave-flash', id: 'Player', width: '100%', height: '100%',
  				quality: 'medium',
  			};
  			params = {
  				flashvars: {
  					'movieOwner': 'African+Vulture%E2%84%A2', 'movieOwnerId': '0uWOI2JiCdHU', 'movieId': '', 'movieLid': '0', 
  					'movieTitle': 'Test',
  					'movieDesc': 'This+video+is+ment+for+testing+out+this+video+player.', 'userId': '', 'username': '', 'uemail': '', 'ut': '-1',
  					'numContact': '', 'apiserver': '/', 'duration': '92', 'playcount': '0', 
  					'thumbnailURL': 'https://josephcrosmanplays532.github.io/img/demo.png', 'copyable': '0', 'isPublished': '0', 'ctc': 'go', 
  					'tlang': 'en_US',
  					'is_private_shared': '1', 'autostart': '0', 'appCode': 'go', 'is_slideshow': '0', 'originalId': '0zEt_fo4L-5k', 
  					'is_emessage': '0', 'storePath': process.env.STORE_URL + '/<store>',
  					'clientThemePath': process.env.CLIENT_URL + '/<client_theme>',
  					'animationPath': process.env.SWF_URL + '/', 'isEmbed': '1', 'refuser': null, 'utm_source': null, 'uid': null, 
  					'isTemplate': '0',
  					'showButtons': '1', 'chain_mids': '', 'averageRating': 5, 'ratingCount': '48', 'fb_app_url': '/', 'ad': 0, 'endStyle': 0, 
  					'isWide': 0, 'pwm': 1, 's3base': 'https://josephcrosmanplays532.github.io/img',
  				},
  				allowScriptAccess: 'always',
  				allowFullScreen: 'true',
  				movie: process.env.SWF_URL + '/player.swf', // 'http://localhost/player.swf'
  			};
  			break;
  		}
  
  		default:
  			return;
  	}
  	res.setHeader('Content-Type', 'text/html; charset=UTF-8');
  	Object.assign(params.flashvars, query);
  	res.end(`<script>document.title='${title}',flashvars=${JSON.stringify(params.flashvars)}</script><body style="margin:0px">${toObjectString(attrs, params)
  		}</body>${stuff.pages[url.pathname] || ''}`);
  	return true;
  }
  